简体   繁体   中英

How to get the text from anchor tag using Jquery

The following is my anchor tag........

<display:setProperty name="paging.banner.full" value='<p><span id="hix-pagination"><span> <a id="id1" class="prev" href="{1}">&#9668;&#9668;</a>

And I tried the following using jquery but did not get any positive result.....

alert($('#id1').text());
      alert($('#id1').html());
      alert($('#id1').val());

You have right selector, if you have jQuery included successfully then you may need document.ready also check if you get html out of DOM

Live Demo

$(function(){
   alert($('#id1').html());
});

Refer this link :

How to get anchor text/href on click using jQuery?

Get text from anchor tag

href:

$(function(){
$('div.res a').click(function(){
alert($(this).attr('href'));
 });
});

Text:

$(function(){
$('div.res a').click(function(){
alert($(this).text());
 });
});
$(document).ready(function() 
        { 
            $("#id1").click(function() {
            alert($(this).text());
            return false;
            }); 
        } 
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM