You have no a
inside the element with the class PageNumber
.
$(".PageNumber")
or even $("a.PageNumber")
if you want to specify it a bit more
You also are looking for an input
next to the $(".PageNumber")
. But its next to the li
so use var pagenum = $(this).parent().next('.page').val();
You are also using $(this).attr(pagenum);
but not sure what you are trying to set or get the value of the attribute.
$(document).ready(function() {
$(".PageNumber").each(function(index, element) {
var pagenum = $(this).parent().next('.page').val();
var linkk = $(this).attr("data-page");
var linktext = $(this).text();
//$(this).attr(pagenum);
$(this).text(pagenum);
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<li><a class="PageNumber" data-page="" data-href="home.htm">1</a></li>
<input type="hidden" value="1" class="page" />
<li><a class="PageNumber" data-page="" data-href="home.htm">1</a></li>
<input type="hidden" value="2" class="page" />
<li><a class="PageNumber" data-page="" data-href="home.htm">1</a></li>
<input type="hidden" value="3" class="page" />
0
solved get the href in the li