Git Product home page Git Product logo

Comments (8)

matthewmueller avatar matthewmueller commented on May 20, 2024 6

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.

ironchefpython avatar ironchefpython commented on May 20, 2024 4

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.

siddMahen avatar siddMahen commented on May 20, 2024

I think that we should stick to the jQuery spec. So .html() should both return and set innerHTML.

from cheerio.

matthewmueller avatar matthewmueller commented on May 20, 2024

Yah.. but jQuery doesn't have a good way of getting "outerHTML".

from cheerio.

siddMahen avatar siddMahen commented on May 20, 2024

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.

ironchefpython avatar ironchefpython commented on May 20, 2024

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.

matthewmueller avatar matthewmueller commented on May 20, 2024

Jeez @ironchefpython you're on fire! I like it. Added to master.

from cheerio.

ironchefpython avatar ironchefpython commented on May 20, 2024

The following assertion fails:

      $.html($('<span>baz</span>')).should.equal('<span>baz</span>');

from cheerio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.