Reputation: 630
I have a php code that generates some <a>
tags and the final output looks like:
<div id='link1'>
<a style="font-size:10pt; color: #008056" href="somelink">Name</a>
<b>;</b>
</div>
My question is how can I count all of the semicolons in that div with jquery?
Upvotes: 4
Views: 2854
Reputation: 82251
To get including those in the style attribute,Try this:
alert($('#link1').html().split(";").length - 1);
And to get without one that are there in attributes:
alert($('#link1').html().replace(/(<([^>]+)>)/ig,"").split(";").length - 1);
Update: To find one occurence of ;
in a and remove it:
$('#link1 a').each(function(){
if($(this).html().split(";").length==2){
$(this).html($(this).html().replace(";",""))
}});
Upvotes: 5
Reputation: 59292
I don't know what you are up to, but if you need it, then you can do:
$('#link1').html().match(/;/g).length
/;/g
is the regex that will match all ;
Upvotes: 5