how can i transform a hashtag in a text to bold using jquery?

@Chirs try this in your webpage

function FormatText()
  {
  var txt =document.getElementById("mytext").innerHTML;
   var matches = txt.match(/#\w+/g);
   if(matches==null)
    return;
    
   for(i=0;i<matches.length;i++)
   {
     txt=txt.replace(matches[i],"<b>"+ matches[i] +"</b>")
   }
   document.getElementById("mytext").innerHTML=txt;
  
  }
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Document</title>
</head>
<body onload="FormatText();">
  <div id="mytext">
    I love #coding using JQuery/JavaScript on #WebPages.
  </div>
</body>
</html>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top