I want to pass <li> id or value
in onclick
event. here is my exiting code.
<li onclick="getPaging(this.value)" id="1" value="1">1</li>
<li onclick="getPaging(this.value)" id="2" value="2">2</li>
here is the javascript code
function getPaging(str)
{
$("#loading-content").load("dataSearch.php?"+str, hideLoader);
}
<li>
s don't have avalue
- only form inputs do. In fact, you're not supposed to even include thevalue
attribute in the HTML for<li>
s.You can rely on
.innerHTML
instead:Or maybe the
id
:However, it's easier (and better practice) to add the click handlers from JavaScript code, and not include them in the HTML. Seeing as you're already using jQuery, this can easily be done by changing your HTML to:
And use the following JavaScript:
This will add the same click handler to all your
<li class="clickMe">
s, without requiring you to duplicate youronclick="getPaging(this.value)"
code for each of them.Try like this...
or unobtrusively
using just
Try this:
I prefer to use the HTML5 data API, check this documentation:
A example