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.
Thanks.
Here is the fiddle: https://jsfiddle.net/swaprks/L1rq4o7a/
Use jquery and add the following to your javascript:
$(".topmid-left b").html("My Site 'something.com'");
try this:
<script>
var str = 'your text';
$( "b" ).html( str );
or
$("b").text(YOUR_TEXT)
</script>
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'
console.log(repText);
// assign new text into html <b> tag.
$("span.topmid-left b").text(repText);
Working Jsfiddle : https://jsfiddle.net/LxcLb012/2/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.