javascript - JS multiple function execution -


i using youtube loadingbar tool found @ www.onextrapixel.com, , it's pretty straightforward regards everything.

however, have multiple <a> tags have different href attributes , load content area (target) different content. problem when initialize loadingbar function class, say:

$('ajax-call').loadingbar(options); 

and have multiple tags same class say:

<a id ="link1" class = "ajax-call" href="hello1.html" data-type="post" data-target="#content_area">link 1</a> <a id ="link2" class = "ajax-call" href="hello2.html" data-type="post" data-target="#content_area">link 2</a> <a id ="link3" class = "ajax-call" href="hello3.html" data-type="post" data-target="#content_area">link 3</a> <a id ="link4" class = "ajax-call" href="hello4.html" data-type="post" data-target="#content_area">link 4</a> 

in example have 4 links, ajax call, along success , done functions, repeated 4 times. each time loads same (correct) content , executes same functions (correct functions) each respective link, 4 times, results in messed everything, since initializing other objects (which initialized 4 times).

all content looks correct nothing in content area works (modals, etc.).

if make 1 link in side menu, works fine. if initialize each link separately id, works fine, if group them in 1 class, happens. how solve this?

classes starts period

$('.ajax-call').loadingbar(options); 

and looks plugin poorly written, not return this.each(function().. does

$.fn.loadingbar = function(options){     el   = $(this),     href = el.attr("href"),     target = el.data("target"),     ...etc 

so calling on collection of elements doesn't work properly, try

$('.ajax-call').each(function() {     $(this).loadingbar(options); }); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -