javascript - Remove placeholders using jQuery -
i have following code , want remove placeholder.
<div class="myclass"> <p><a href="http:[sitename]">[sitetile]</a>[change too]someothercontent</p> </div>
and want change above markup event using jquery:
<div class="otherclass"> <p><a href="http:yahoo.com">changemaincontent</a>changesomeothercontent</p> </div>
create object index named part want replace (inside brackets) , assign value it. use $.each
-function iterate on object , replace values in html 1 object. after assign new html-string element.
var change = { 'sitename': 'yahoo.com', 'sitetile': 'changemaincontent', 'change too': 'change' }; var $elem = $('.myclass > p'); //cache element var html =$elem.html(); //get html-string $.each(change, function(index, value){ //iterate on object html = html.replace('[' + index + ']', value); //replace values }); $elem.html(html); //assign new html-string
reference
Comments
Post a Comment