jquery - Passing data from jsp to javascript -
i have ajax call returns html, call $("#my-div").html(data) in javascript.
however, using twbspagination requires setting element through javascript.
the html element defined as
<input type="hidden" name="totalpagecount" id="totalpagecount" value="${totalpagecount}"/> <ul id="pagination" class="pagination-sm"></ul>
and javascript is:
callingfunction() { data = doajaxcall().done(myfunction); } myfunction(data) { $('#pagination').twbspagination({ totalpages: $("#totalpagecount").val(), visiblepages: 5, onpageclick: function (event, page) { ... } }); $("#my-div").html(data); }
even though have confirmed hidden field totalpagecount has right value, $("#totalpagecount").val() returns empty string. i'm guessing because it's looking element exists inside html of data, not part of jquery looking at.
what standard way pass kind of data?
i able solve switching around order executed javascript.
$("#my-div").html(data); $('#pagination').twbspagination({ totalpages: $("#totalpagecount").val(), visiblepages: 5, onpageclick: function (event, page) { ... } });
by replacing html first, jquery able find element.
Comments
Post a Comment