Reputation: 7106
I need to change text inside html tags, using jQuery/javascript. For example, I need to change this:
<a id="id_1" href="www.google.com"> TEST </a>
into this:
<a id="id_1" href="www.google.com"> SUCCESS </a>
This should be done in regular time intervals, through a jQuery function, but that timing part I know how to do - I just don't know how to change this text. Any help is welcome, since this is the first time I am trying to do something like this.
EDIT: Sorry for what seems to be a stupid newbie question everyone. I have tried searching online, but whatever I typed in gave me results such as changing field values, or element attributes. I will choose the first answer, and once again, sorry for the question.
Upvotes: 0
Views: 185
Reputation: 197
first way is:
$("#id_1").text('SUCCESS');
if u want to change all links with href google use
$("a[href^='http://www.google.com']").text('SUCCESS');
and u can change class with:
$("#id_1").css('class','class2')
Upvotes: 0
Reputation: 148180
You can use text() of html() method of jquery to change the content of anchor,
$('#id_1').text("SUCCESS");
if you want to set the html
$('#id_1').html("SUCCESS");
Upvotes: 1
Reputation: 3811
You can simply update the text as follows:
$("#id_1").text("SUCCESS");
Upvotes: 4
Reputation: 1075755
If you look at the jQuery API documentation, you'll see a function called jQuery
(also usually $
) that can find elements based on a CSS selector, and another called html
. You can use them to do this.
$("#id_1").html(" SUCCESS ");
If you take an hour to read through the API docs (it really only takes that long), you'll find a lot of very useful information there. Also consider reading up on the DOM (Document Object Model), which jQuery uses to perform (most of) its work. Various DOM documents can be found on the W3C DOM page.
Upvotes: 3