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

Changing Elements/Attributes

You can replace or modify your HTML using .html(). However, the more likely scenarios is to add more information to the HTML, remove something, or append other elements. Let’s look at these examples next.

Append/Remove Items

jQuery supports building parts of your HTML using code. Once you have a selection, you can use the methods .remove, .replaceWith(), .before, .after, .prepend, and .append. This is true if your selection is an element node or the HTML content.

For example, the following code appends an additional <li> item to the navbar list from Listing 18.1.

$('#navbar').append('<li>Import ride date from race computer</li>');

As another example, suppose you want to work with each ...

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