jquery - change content of html <b> tag

I have set of frames and html pages . I have selected one of the frames html element from another html page and I want to change the content using jquery.

Here , I want to change "test.com" to "something.com" . Please let me know , how to achieve this.

HTML element in frame 0 :

<span class="topmid-left">Connected to <b>My Site 'test.com' </b> </span>

The same element can be selectable by jquery by setting context :

**query -**  $("b",window.frames[0].document)

**result -** <b>?My Site 'test.com' ?</b>?

How to change the content of tag here.


Answers 1

  • Try this it will work :

    Html :

    <span class="topmid-left">Connected to <b>My Site 'test.com'</b> </span>

    Script :

    // return the inner text of <b>.
    var boldText = $("span.topmid-left b").text(); 
    // returns the array of length 3.
    var splitArr = boldText.split('\''); 
    // returns test.com
    var text = splitArr[1];
    // replace the text.com with abc(or any text you want).
    var repText = boldText.replace(text, "xyz"); 
    // [Output] My Site 'xyz'
    // assign new text into html <b> tag.
    $("span.topmid-left b").text(repText);

    Working Jsfiddle : https://jsfiddle.net/LxcLb012/2/

Related Articles