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
Release: 2016-05-16 16:52:03
Original
1345 people have browsed it

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
Related labels:
js
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