Timmy Von Heiss Timmy Von Heiss - 2 months ago 7
jQuery Question

how to get the value of a modal href id

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.

Answer

Use only 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>