javascript - How to replace all "/" within a p tag -


i replace forward slashes within p tag cannot see doing wrong.

$(document).ready(function() {    var content = $("p").text();    content.replace(/\//g, 'forwardslash');  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <p>yoyoyo / yoyoyoy / yiyyiyiyi ddwqd w/ dwdwdw/ dwd / dwd /</p>  <div>yoyoyo / yoyoyoy / yiyyiyiyi ddwqd w/ dwdwdw/ dwd / dwd /</div>

the reason want because site making requires forward slashes different colour text within tag , building site within cms trying make easy edit. crude way of doing make client paste spans class names or inline styles. can 1 of things him automatically using , code above.

you on right track. but, know replace() not take string reference , modify it. rather, returns result , have use result

$(document).ready(function() {    $('p').each(function() {      var content = $(this).text();        content = content.replace(/\//g, 'forwardslash');      $(this).text(content);    });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <p>yoyoyo / yoyoyoy / yiyyiyiyi ddwqd w/ dwdwdw/ dwd / dwd /</p>  <p>yoyoyo / yoyoyoy / yiyyiyiyi ddwqd w/ dwdwdw/ dwd / dwd /</p>


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -