Chapter 8
Advanced Selectors, Traversing, and DOM Manipulation
Section 8
Revisiting Attribute Manipulation
We often create new elements in our jQuery code by providing an HTML string to the $() function or the other DOM insertion functions. This technique is fast and concise. There are circumstances when it is not ideal though. We might, for instance, want to escape special characters from text before it is used, or apply style rules that are browser-dependent. In these cases, we can create the element and then chain on additional jQuery methods to alter it, as we have done many times already. In addition to this standard technique, the $() function itself provides an alternative syntax to achieve the same result. Let’s look at this in more detail.