I have some lines of HTML code that are like this:
<li><a href="#" class="lstItem">Testing jQuery [First Bracket]</a></li>
<li><a href="#" class="lstItem">Loving jQuery [Second one]</a></li>
I’m trying to replace what’s inside the bracket with nothing onLoad, like this:
var item = $(".lstItem").text();
var match = item.match(/\[(.*?)\]/);
item = item.replace(match[0], "");
But nothing changes. What’s wrong and how to correct this?
After using jimbojw‘s suggestion I’m getting a Uncaught ReferenceError: text is not defined at this particular line:
oldtext = $item.text,
this will do the job for you:
you are splitting your code in too much lines, also your need to run replace for each individual element separately.
see your example in jsFiddle: http://jsfiddle.net/eKn3Q/7/