Comments (8)
Yah, I tend to agree with you. I want it to be incredibly easy to get the outer HTML though, because most of my use cases involve manipulating the html string, then rendering the whole string.
I'm realizing though, that in jQuery i never needed to get the outer HTML, because I'm never rendering the whole document. So this is what I'm thinking:
$('.orange').html() // => returned innerHTML
$.html() // => Returned entire HTML string
This way we are adhering to the jQuery spec while extending the spec gracefully to cover a major use case of server-side rendering.
from cheerio.
I'm fine with that, also, I'd allow $.html to take an optional cheerio parameter, so in code like the following:
var span = $("<div><span>foo</span><span>bar</span></div>").children().get(1);
span.html() // => returns "bar"
$.html(span) // => returns "<span>bar</span>"
The major advantage to that, is if I wanted jQuery to behave the same way, I could write a jQuery plugin for that in 30 seconds.
from cheerio.
I think that we should stick to the jQuery spec. So .html() should both return and set innerHTML.
from cheerio.
Yah.. but jQuery doesn't have a good way of getting "outerHTML".
from cheerio.
Then it would be better to provide a separate function to get and set outerHTML, rather than mix and match with .html()
.
Plus, it's better to break functionality early on, rather than later.
from cheerio.
I'd like to be able to use this library to execute the same manipulation on the server as I do in the browser. jQuery compatibility seems like the highest priority. I think .html()
should read and write innerHTML.
I'd vote for adding a special method like .toHtml()
which would return an array of strings if you need to dump outerHTML of the collection for debugging purposes.
from cheerio.
Jeez @ironchefpython you're on fire! I like it. Added to master.
from cheerio.
The following assertion fails:
$.html($('<span>baz</span>')).should.equal('<span>baz</span>');
from cheerio.
Related Issues (20)
- Incorrect code example in intro documation
- Multiple html tags are deleted HOT 2
- TypeError: cheerio.fromURL is not a function HOT 6
- How to "replaceWith" on plain text, which is not a DOM Elements? HOT 5
- Unsafe legacy renegotiation disabled
- text() method merges text parts HOT 3
- Bug: Crawler reached the maxRequestsPerCrawl limit of 1 requests and will shut down soon HOT 1
- Bug: XML tags with mixed case, when using lowerCaseTags: true, selectors will be lowercased before comparing with the xml tag name
- exporting function from battiers
- Error with nextjs 14 HOT 1
- Cherrio is unable to retrieve content with property of og in the meta tag HOT 3
- If the page is SPA (such as Vue), can't I use Cheerio to retrieve the content of the website that has been fully loaded HOT 1
- whitespace normalization removes NBSP chars in xmlMode HOT 1
- Can´t select elements based on their position in the document HOT 2
- Live Editor Result Panel Blank
- how to add defer to script tag HOT 1
- Weird behaviour with HTML entities within XML content
- Behaving exceptionally in template syntax containing curly braces
- error TS2724: '"/app/node_modules/cheerio/lib/esm/index"' has no exported member named 'Text'
- Using XML format for obfuscation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cheerio.