if you have
<div id="data" onclick="handleData(1)">Datum 1</div>
and you want to late bind instead:
<div id="data">Datum 1</div>
<script>
$("#data").click(function() {
handleData(1);
})
</script>
How do you pass that parameter 1? do you have to do something like this:
<div id="data" data="1">Datum 1</div>
<script>
$("#data").click(function() {
handleData($(this).attr("data"););
})
</script>
I assume you're using jQuery.
If so, I'd take advantage of jQuery's support for the HTML5
data-
attribute using thedata()
(docs) method . It will in all browsers.Notice that I changed the attribute to
data-number
, and accessed it with.data("number")
. This requiresjQuery 1.4.3
or later.From the docs: