-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.html() returns outerHTML, while .html(html) sets innerHTML #16
Comments
I think that we should stick to the jQuery spec. So .html() should both return and set innerHTML. |
Yah.. but jQuery doesn't have a good way of getting "outerHTML". |
Then it would be better to provide a separate function to get and set outerHTML, rather than mix and match with Plus, it's better to break functionality early on, rather than later. |
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 I'd vote for adding a special method like |
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:
This way we are adhering to the jQuery spec while extending the spec gracefully to cover a major use case of server-side rendering. |
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. |
Jeez @ironchefpython you're on fire! I like it. Added to master. |
The following assertion fails: $.html($('<span>baz</span>')).should.equal('<span>baz</span>'); |
I can't believe this one has gone unnoticed. I'm not really sure what to do about it actually. I think it's more useful how it is right now, but I don't like the asymmetry. I also don't like straying away from the jQuery API.
What do you guy's think?
The text was updated successfully, but these errors were encountered: