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

Examples of conversion between jQuery objects and DOM objects and strings

黄舟
黄舟Original
2017-08-13 10:13:311508browse

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): $('e388a4556c0f65e1904146cc1a846beeI am a little flower of the motherland94b3e26ee717c64999d7867364b1b4a3')

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;
}

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!

Statement:
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