Friday, 15 June 2012

html - recognize tag in jquery,while looping through each node - -



html - recognize <br> tag in jquery,while looping through each node - -

here problem , really killing me becauseit has simple solution. check out jsfiddle

<body> <p> first paragraph , prepend without problems @ </p> <span> simple span element, , prepend without problems @ </span> <em> heres em , works </em> <p> here para , works , @ next line <br>br starts here prepend, ladies , gentlement,,nada. </br> </p>

$("*", document.body).each(function () { $(this).prepend('<b><font color="red"> soccer </font></b>'); });

you find simple set of html tags few randomly placed <p> , <span> tags. have written little jquery (2 lines function) loops through tags in body of page , prepends piece of html each tag.

unfortunately, <br> tags not seem follow other tags follo. not prepended html , can't figure out.

it's because <br/> tag can't have children elements or content https://developer.mozilla.org/en-us/docs/html/element/br.. if utilize .before()/.after() show sibling wanted.

http://jsfiddle.net/gmbpt/

jquery html prepend

No comments:

Post a Comment