Reputation: 137
I would like to remove the Paktutorial text using jquery. But I am unable to get the text replaced. The second div has a name dynamically created.
$(document).ready(function() {
var text= $('#frei_user_brand').text().replace("Paktutorial", "Good News");
$('#frei_user_brand').text(text);
});
<div id="frei_user_brand" class="frei_user_brand">
<div id="frei" class="frei" style="height: 18px; ">Sample Text</div>
<div id="big696power" class="big899power">
<font size="1">
<a href="http://paktutorial.com" target="_blank">Paktutorial</a>
</font>
</div>
</div>
Upvotes: 0
Views: 467
Reputation: 7930
You can also use this
var text= $('#big696power').children().children('a').text().replace("Paktutorial","pippo") ;
Inside the $(), you can put also the code which generates the name of the div, for example
var text= $('#<?php echo $div;?>?').children().children('a').text().replace("Paktutorial","pippo") ;
which I use frequently.
If you know that the href will not change inside the you can also use the other suggestion, by letting js to search the element by using filter:
Search with exact match:
$(E[A=B])
or Search with partial match:
$(E[A^=B])
where E is the element in the DOM or the selector (a, input, div,...), A is the property (href, name, value,...) and B is the value.
Upvotes: 0
Reputation: 5173
$(document).ready(function() {
$('#frei_user_brand a').text("Good News");
});
Upvotes: 1
Reputation: 2281
try this
var text= $('#frei_user_brand a').text().replace("Paktutorial", "Good News");
$('#frei_user_brand a').text(text);
Upvotes: 1