The following editor will bring you an example of conversion between jQuery objects, DOM objects and strings. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look
1. String---------->jQuery object
$(HTML string): $('
I am a little flower of the motherland
')To be added list
##2 , jQuery object---------->DOM object
Subscript selection method (principle: jQuery is the array form of DOM):$("h2") [1]Use the .get(index) function3. String ----------->DOM object
Write a script functionfunction parseDom(nodelist) { //nodelist是html文本字符串 var objE = document.createElement("p"); objE.innerHTML = nodelist; return objE.childNodes; }
4. DOM object--------->String
Use the function .html()## in jQuery#$(Selector).html();//Use the selector to select the DOM object you want to convert into a string, and then use the html() function and it’s done
The above is the detailed content of Examples of conversion between jQuery objects and DOM objects and strings. For more information, please follow other related articles on the PHP Chinese website!