I am trying to call a function using every object found in jQuery selection
<a href="#" class="can-click" data-code="a">a</a> <a href="#" class="can-click" data-code="b">b</a> <a href="#" class="can-click" data-code="c">c</a> <a href="#" class="can-click" data-code="d">d</a>
Each item has a data code value.
<p class="output" data-value="1"></p> <p class="output" data-value="2"></p> <p class="output" data-value="3"></p>
Each p element has a data value
$(document).ready(function () { $(".can-click").click(function () { var code = $(this).data("code"); $("output").each(Display(code)); }); });
What I want to do is that when you click on anchor a you will get a warning showing you the data code from the click of the anchor and the data value for each p, with the code attached by woud, I want 3 warnings.
function Display(code) { var p = $(this); var value = p.data("value"); alert(code + " " + value); }
here is the link to the code in jsfiddle http://jsfiddle.net/mikeu/XFd4n/
Mike u
source share