0

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.

2
  • check this site docs.jquery.com Commented Nov 6, 2012 at 15:06
  • I have tried searching online, but all I get is how to change values of fields, or attributes. Commented Nov 6, 2012 at 15:06

5 Answers 5

4

You can simply update the text as follows:

$("#id_1").text("SUCCESS");
Sign up to request clarification or add additional context in comments.

Comments

3

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.

2 Comments

This did it, and thanks a lot for the quick reply. I will look through the documentation.
Yes, of course - yesterday I couldn't accept it right away, had to wait 15 minutes.
1

You can use text() of html() method of jquery to change the content of anchor,

Live Demo

$('#id_1').text("SUCCESS");

if you want to set the html

$('#id_1').html("SUCCESS");

Comments

1

It is very simple:

$("#id_1").text('SUCCESS')

Comments

0

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.