How to change text of anchor tag on click using jquery?

change anchor tag text using javascript
jquery change anchor href
how to add text to anchor tag using jquery
change div text jquery
change text value jquery
jquery get anchor tag href value
adding href using jquery
text javascript

I want to change text of anchor tag on click event using jquery.

Anchor tag :

 <a id="view_email" href="#"><i class="fa fa-envelope"></i> View Email</a>

JQuery Code :

<script type="text/javascript">
$(document).ready(function(){
    $("#view_email").click(function(){
        $(this).text() = "abc@gmail.com";
    });
});
</script>

$(document).ready(function(){
    $("#view_email").click(function(){
        $(this).text("abc@gmail.com");//you will loose <i> tag
        //$(this).html("<i class="fa fa-envelope"></i> View Email")//better to use html instead of text.
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="view_email" href="javascript:void(0);"><i class="fa fa-envelope"></i> View Email</a>

replace anchor text with jquery, How do I change the text anchor tag in jQuery? As your title implies, you want to get the href value on click. Simply select an element, add a click event listener and then return the href value using either of the aforementioned methods. var anchor = document.querySelector('a'), button = document.getElementById('getURL'), url = anchor.href; button.addEventListener('click', function (e) { alert(url); });

.text() is a method and you cant assign to this method call;

try

<script type="text/javascript">
    $(document).ready(function(){
    $("#view_email").click(function(){
        $(this).textContent = "abc@gmail.com";
    });
    });
</script>

How to get the value from anchor tag using jQuery?, How do I find the value of an anchor tag? Get text from anchor tag. I got the text of all the anchor tags combined in my code: How to get the text from anchor tag using Jquery. 0.

since the text() function will also replace the envelope icon with text , render the text using html() along with the icon as shown below:

$(document).ready(function(){
    $("#view_email").click(function(){
        $(this).html("<i class='fa fa-envelope'></i>abc@gmail.com");
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="view_email" href="#"><i class="fa fa-envelope"></i> View Email</a>

Changing anchor text, Changing anchor text. in Using jQuery • 6 years ago. Hi,. Some can help me with the following: Copy code. <div style="" id="tabs" >; <ul class="ui-tabs-nav  jQuery Forum Move this topic Forum : Getting Started Using jQuery Using jQuery Plugins Using jQuery UI Developing jQuery Core Developing jQuery Plugins Developing jQuery UI QUnit and Testing About the jQuery Forum jQuery Conferences jQuery Mobile Developing jQuery Mobile

jQuery: Change the hyperlink and the text of a existing link , jQuery core Exercises with Solution: Write jQuery Code to change the hyperlink and the text of a existing link. >PostgreSQL Tutorial</a> </body> </html>. JavaScript Code : $("a").attr("href"  See the Pen jquery-core-exercise-9 by w3resource (@w3resource) on CodePen. Contribute your code and comments through Disqus. Previous: Write a jQuery Code to add a tag at the beginning of the list item, containing the index of the list item.

How to replace text of an anchor tag with JavaScript/jQuery, With jQuery, you can use the text() method to replace text of an anchors tag with a specific text. The following code demonstrates this. JS; HTML. JS. In this post we will learn how to change or add JavaScript function on the onclick event for the anchor tag. Infact, you can use this methodology add/change JavaScript function for almost any event and on elements which support such events.

How to Change href Attribute of a Hyperlink Using jQuery, You can use the jQuery .attr() method to dynamically set or change the value of href attribute of a link or anchor tag. This method can also be used to get the  In this post, we will see how to replace text of an anchor tag with JavaScript and jQuery. 1. jQuery. With jQuery, you can use the text() method to replace text of an anchors tag with a specific text. The following code demonstrates this.

Comments
  • $(this).text() = "abc@gmail.com"; is wrong
  • So add a class....
  • Possible duplicate of how to change text value within an element?