O'Reilly logo

Microsoft Visual Studio 2015 Unleashed, Third Edition by Mike Snell, Lars Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Accessing Selection Content

Your selected objects in jQuery are returned as a jQuery object that maintains a reference to the DOM node. This is different from objects returned by the document selectors. Therefore, jQuery provides its own methods for working with your selected results. Chief among them are .html(), .text()., and .val().

The .html() method returns the HTML inside the selected element. If more than one element is in your results, only the HTML contained inside the first element is returned. As an example, the following selection returns all the <li> items inside the <ul> in Listing 18.1.

var sel = $('#navbar').children('li');var ht = sel.html();

However, the call to .html() in the preceding code returns ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required