Jquery count specific character in div -


i have php code generates <a> tags , final output looks like:

<div id='link1'> <a style="font-size:10pt; color: #008056" href="somelink">name</a> <b>;</b> </div> 

my question how can count of semicolons in div jquery?

to including in style attribute,try this:

  alert($('#link1').html().split(";").length - 1); 

and without 1 there in attributes:

  alert($('#link1').html().replace(/(<([^>]+)>)/ig,"").split(";").length - 1); 

working demo

update: find 1 occurence of ; in , remove it:

$('#link1 a').each(function(){  if($(this).html().split(";").length==2){   $(this).html($(this).html().replace(";","")) }}); 

working demo


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -