Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the value of anchor using jquery

<div class="dataTables_paginate paging_simple_numbers" id="myTable_reports_view_paginate">
    <a class="paginate_button previous disabled" aria-controls="myTable_reports_view" data-dt-idx="0" tabindex="0" id="myTable_reports_view_previous">&lt;&lt;</a>
    <span>
        <a class="paginate_button current" aria-controls="myTable_reports_view" data-dt-idx="1" tabindex="0">1</a>
        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="2" tabindex="0">2</a>
        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="3" tabindex="0">3</a>
        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="4" tabindex="0">4</a>
        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="5" tabindex="0">5</a>
        <span class="ellipsis">…</span>
    <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="6" tabindex="0">33</a>
    </span>
    <a class="paginate_button next" aria-controls="myTable_reports_view" data-dt-idx="7" tabindex="0" id="myTable_reports_view_next">&gt;&gt;</a>
</div>

My question is how to get the value 33 using jquery.

like image 954
user3302950 Avatar asked Jan 28 '26 12:01

user3302950


2 Answers

$('.paginate_button').last().text()

looks like you have updated the question, which makes the answer incorrect, so below is my updated answer.

$('#myTable_reports_view_paginate span > a.paginate_button').last().text()
like image 163
atinder Avatar answered Jan 30 '26 06:01

atinder


Use :last selector , to avoid next use :not()

alert($('a.paginate_button:not(.next):last').text())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="dataTables_paginate paging_simple_numbers" id="myTable_reports_view_paginate">
  <a class="paginate_button previous disabled" aria-controls="myTable_reports_view" data-dt-idx="0" tabindex="0" id="myTable_reports_view_previous">&lt;&lt;</a>
  <span>
                        <a class="paginate_button current" aria-controls="myTable_reports_view" data-dt-idx="1" tabindex="0">1</a>
                        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="2" tabindex="0">2</a>
                        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="3" tabindex="0">3</a>
                        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="4" tabindex="0">4</a>
                        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="5" tabindex="0">5</a>
                        <span class="ellipsis">…</span>
  <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="6" tabindex="0">33</a>
  </span>
  <a class="paginate_button next" aria-controls="myTable_reports_view" data-dt-idx="7" tabindex="0" id="myTable_reports_view_next">&gt;&gt;</a>
</div>

You can also use last() and not()

alert($('a.paginate_button').not('.next').last().text())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="dataTables_paginate paging_simple_numbers" id="myTable_reports_view_paginate">
  <a class="paginate_button previous disabled" aria-controls="myTable_reports_view" data-dt-idx="0" tabindex="0" id="myTable_reports_view_previous">&lt;&lt;</a>
  <span>
                        <a class="paginate_button current" aria-controls="myTable_reports_view" data-dt-idx="1" tabindex="0">1</a>
                        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="2" tabindex="0">2</a>
                        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="3" tabindex="0">3</a>
                        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="4" tabindex="0">4</a>
                        <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="5" tabindex="0">5</a>
                        <span class="ellipsis">…</span>
  <a class="paginate_button " aria-controls="myTable_reports_view" data-dt-idx="6" tabindex="0">33</a>
  </span>
  <a class="paginate_button next" aria-controls="myTable_reports_view" data-dt-idx="7" tabindex="0" id="myTable_reports_view_next">&gt;&gt;</a>
</div>
like image 32
Pranav C Balan Avatar answered Jan 30 '26 07:01

Pranav C Balan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!