html - Javascript find all text except those in <a> tag -
i have div, , div can (or cannot) have html elements children. javascript, need find occurrences of word inside div, except in <a>
tag.
for example:
<div id="dictionable"> lorem ipsum dolor sit amet, consectetur adipiscing elit. <br/><br/> <a href="#lorem">lorem</a> <br/><br/> <p>lorem</p> </div>
i tried ultra low capabilities build regex, failing miserably. googled , found this:
var pattern = new regexp('(lorem)(?![^<]*>|[^<>]*</)', 'gim');
this regex finds every occurrence of "lorem" not in every tag. need exclude tag.
could me?
no regex. absolutely no regex. nuh-uh. nope.
var copy = document.getelementbyid('dictionable').clonenode(true), links = copy.getelementsbytagname('a'), l = links.length, i; for( i=l-1; i>=0; i--) { // work in reverse order when deleting stuff, it's safer! links[i].parentnode.removechild(links[i]); } var result = copy.textcontent || copy.innertext;
boom!
Comments
Post a Comment