easy way to parse HTML into jQuery usable object -
say want insert large block of html directly element, example:
<div class ="test"> <p class ="ptest"> mauris blandit <span class ="span1">aliquet elit,</span> eget tincidunt nibh pulvinar a. cras ultricies ligula sed magna dictum porta. </p> </div>
its easy with:
jquery.append("")
however means have format html first (removing line breaks, replacing " ' etc).
is there method automatically within jquery or need manually?
ive run same problem couple of times en helped me lot. maybe can to.
http://api.jquery.com/jquery.parsehtml/
<div id="log"> <h3>content:</h3> </div> <script> var $log = $( "#log" ), str = "hello, <b>my name is</b> jquery.", html = $.parsehtml( str ), nodenames = []; // append parsed html $log.append( html ); // gather parsed html's node names $.each( html, function( i, el ) { nodenames[ ] = "<li>" + el.nodename + "</li>"; }); // insert node names $log.append( "<h3>node names:</h3>" ); $( "<ol></ol>" ) .append( nodenames.join( "" ) ) .appendto( $log ); </script>
Comments
Post a Comment