Home > Web Front-end > JS Tutorial > Examples of conversion between jQuery objects and DOM objects and strings

Examples of conversion between jQuery objects and DOM objects and strings

黄舟
Release: 2017-08-13 10:13:31
Original
1621 people have browsed it

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) function

3. String ----------->DOM object

Write a script function


function parseDom(nodelist) { //nodelist是html文本字符串
 var objE = document.createElement("p"); 
 objE.innerHTML = nodelist;
 return objE.childNodes;
}
Copy after login

First put the 'string'--->jQuery---->DOM object

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template