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" to "something" . Please let me know , how to achieve this.
HTML element in frame 0 :
<span class="topmid-left">Connected to <b>My Site 'test' </b> </span>
The same element can be selectable by jquery by setting context :
**query -** $("b",window.frames[0].document)
**result -** <b>My Site 'test' </b>
How to change the content of tag here.
Thanks.
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." to "something." . Please let me know , how to achieve this.
HTML element in frame 0 :
<span class="topmid-left">Connected to <b>My Site 'test.' </b> </span>
The same element can be selectable by jquery by setting context :
**query -** $("b",window.frames[0].document)
**result -** <b>My Site 'test.' </b>
How to change the content of tag here.
Thanks.
Share Improve this question asked Apr 7, 2016 at 6:34 JavaUserJavaUser 26.4k47 gold badges116 silver badges144 bronze badges 5-
1
$("b").text(YOUR_TEXT)
? or$("span.topmid-left b").text(YOUR_TEXT)
– Rayon Commented Apr 7, 2016 at 6:35 - Uncaught TypeError: $(...).text is not a function(…) – JavaUser Commented Apr 7, 2016 at 6:38
-
1
Have you included
jQuery
? – Rayon Commented Apr 7, 2016 at 6:39 - Yes . Thats why I am able to select the text. – JavaUser Commented Apr 7, 2016 at 6:39
- Can you share executable demo/snippet or JSFiddle ? – Rayon Commented Apr 7, 2016 at 6:40
3 Answers
Reset to default 4Here is the fiddle: https://jsfiddle/swaprks/L1rq4o7a/
Use jquery and add the following to your javascript:
$(".topmid-left b").html("My Site 'something.'");
try this:
<script>
var str = 'your text';
$( "b" ).html( str );
or
$("b").text(YOUR_TEXT)
</script>
Learn More
Try this it will work :
Html :
<span class="topmid-left">Connected to <b>My Site 'test.'</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.
var text = splitArr[1];
// replace the text. 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/LxcLb012/2/