change html text from link with jquery

JavascriptJqueryDomHyperlink

Javascript Problem Overview


a simple question here

Is there a way to change the text "click here"

<a id="a_tbnotesverbergen" href="#nothing">click here</a>

in this link

Richard

Javascript Solutions


Solution 1 - Javascript

You have to use the jquery's text() function. What it does is:

> Get the combined text contents of all > matched elements. > > The result is a > string that contains the combined text > contents of all matched elements. This > method works on both HTML and XML > documents. Cannot be used on input > elements. For input field text use the > val attribute.

For example:

> Find the text in the first paragraph > (stripping out the html), then set the > html of the last paragraph to show it > is just text (the bold is gone). > > var str = $("p:first").text(); > $("p:last").html(str); > > Test Paragraph. > > Test Paragraph.

With your markup you have to do:

$('a#a_tbnotesverbergen').text('new text');

and it will result in

<a id="a_tbnotesverbergen" href="#nothing">new text</a>

Solution 2 - Javascript

The method you are looking for is jQuery's .text() and you can used it in the following fashion:

$('#a_tbnotesverbergen').text('text here');

Solution 3 - Javascript

$('#a_tbnotesverbergen').text('My New Link Text');

OR

$('#a_tbnotesverbergen').html('My New Link Text or HTML');

Solution 4 - Javascript

You need J-query library to do this simply:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

First you need to put your element in div like this:

<div id="divClickHere">
<a id="a_tbnotesverbergen" href="#nothing">click here</a>
</div>

Then you should write this J-Query Code:

<script type="text/javascript">
$(document).ready(function(){
$("#a_tbnotesverbergen").click(function(){
$("#divClickHere a").text('Your new text');
});
});
</script>

Solution 5 - Javascript

I found this to be the simplest piece of code for getting the job done. As you can see it is super simple.

for original link text

I use:

    $("#sec1").text(Sector1);

where

   Sector1 = 'my new link text';

Solution 6 - Javascript

From W3 Schools HTML DOM Changes: If you look at the 3rd example it shows how you can change the text in your link, "click here". Example:

<a id="a_tbnotesverbergen" href="#nothing">click here</a>

JS:

var element=document.getElementById("a_tbnotesverbergen"); 
element.innerHTML="New Text";

Solution 7 - Javascript

try this in javascript

 document.getElementById("22IdMObileFull").text ="itsClicked"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRichardView Question on Stackoverflow
Solution 1 - JavascripteKek0View Answer on Stackoverflow
Solution 2 - JavascriptxenonView Answer on Stackoverflow
Solution 3 - Javascriptkarim79View Answer on Stackoverflow
Solution 4 - JavascriptMohammed Alasa'adView Answer on Stackoverflow
Solution 5 - JavascriptDavid WhiteView Answer on Stackoverflow
Solution 6 - Javascriptcbell1977View Answer on Stackoverflow
Solution 7 - JavascriptYitzhak WeinbergView Answer on Stackoverflow