function - jQuery not executing -


so have code in script tags:

$(function(){   $("#news-link-1").click(runaccordion(1));   $("#news-link-2").click(runaccordion(2));   $("#news-link-3").click(runaccordion(3));   $("#news-link-4").click(runaccordion(4));   $("#news-link-5").click(runaccordion(5));   $("#news-link-6").click(runaccordion(6));   $("#news-link-7").click(runaccordion(7));   $("#news-link-8").click(runaccordion(8));   $("#news-link-9").click(runaccordion(9));   $("#news-link-10").click(runaccordion(10));   $("#news-link-11").click(runaccordion(11));   $("#news-link-12").click(runaccordion(12)); }) 

but odd reason, can execute function when there's 1 row (condition) inside.

how can execute function rows inside? or perhaps need if() statement?

edit: if use if() statement in function, each next statement override previous one:

   $(function(){    if ($("#news-link-1").click){        runaccordion(1)    }    if ($("#news-link-2").click){        runaccordion(2)    } }); 

you calling functions on page load. should pass function without calling using (), ie $("#news-link-1").on('click', func), otherwise returned value of function set event handler. since here want pass argument function, should use function:

$("#news-link-1").click(function() {    runaccordion(1); }); 

but suggest adding classes elements , using index method:

var $links = $(".news-links").on('click', function() {      var = $links.index(this) + 1;      runaccordion(i); }); 

now selecting matching target element in runaccordion function can use .eq() method:

var $accordions = $('.accordions'); // ... var $target = $accordions.eq(i); 

please note both index , eq methods zero-based!


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -