简体   繁体   中英

How to get the value of href attribute

From source code:

<a class="nextinst" data-dismiss="modal" data-toggle="modal" href="#401">
    <span class="glyphicon glyphicon-chevron-right"></span>
</a>

I want to get #401

I have unsuccessfully tried

$('.nextinst').attr('href').val()  
$('.nextinst').attr('href').html()
$('.nextinst').attr('href').text()

After I recover it, I then want to check if the modal with that id has been loaded in the DOM.

you can add an ID for that element and call the attr() to get the attribute of href use the this:

  function clickIt(){
    var val = $("#linkHref").attr("href");
    alert(val);
  }

在此处输入图片说明

To get the value of an attribute use attr() :

$('.nextinst').attr('href');

See example:

 $(document).ready(function () { console.log($('.nextinst').attr('href')); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a class="nextinst" data-dismiss="modal" data-toggle="modal" href="#401"> <span class="glyphicon glyphicon-chevron-right"></span> </a>

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