Home >Web Front-end >JS Tutorial >Parse HTML string sample code in JS_javascript tips

Parse HTML string sample code in JS_javascript tips

WBOY
WBOYOriginal
2016-05-16 16:52:031360browse

Add the html statement directly to js, ​​and js will parse the html string into the corresponding HTML statement and display it on the front end.

Copy code The code is as follows:

var el = document.createElement( 'div' );
el.innerHTML = "titleTest< ;a href='test0'>test01test02test03< ;/html>";
el.getElementsByTagName( 'a' ); // Live NodeList of your anchor elements


Apply in jquery:
Copy code The code is as follows:

var el = $( '
' ) ;
el.html("titleTesttest01 test02test03");
$('a ', el) // All the anchor elements
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