The code works for me in this example jsFiddle. I suspect the code is executing too early, and as a result the click
event handlers aren't being bound to the elements (because they don't exist yet). Try wrapping it in a $(document).ready()
call:
$(document).ready(function () {
$('.latestNewsWidgetMoreLink, .latestNewsWidgetMoreButton').click(function () {
total_items = 10;
$(this).parent('div').data('skip', total_items);
});
});
That will ensure the code doesn't execute until the DOM is ready, so the elements will exist and can have event handlers bound.
Note that I've made a couple of adjustments:
- Removed the semi-colons from the
href
attributes of the<a>
elements - was causing a JavaScript syntax error - Using the
.data()
jQuery function rather than.attr()