Note that there are some explanatory texts on larger screens.

plurals
  1. POSimplify JQuery Codes
    primarykey
    data
    text
    <p>Good Day!</p> <p>I'd like to ask something . Is there such a way that could shorten these lines of mine in jquery? I mean specially in the if-else part. Thank you!</p> <hr> <pre><code>$("#banner a").bind("click",function(event){//2 event.preventDefault(); target = $(this).attr("href"); if(target=="#home"){ $("#prevID").attr("class",""); $("#nextID").attr("class","next"); $("#nextID").attr("href","#home"); $("#prevID").attr("href","#home"); }else if(target=="#newsletter"){ $("#prevID").attr("class","prev"); $("#nextID").attr("href","#newsletter"); $("#prevID").attr("href","#newsletter"); }else if(target=="#directions"){ $("#prevID").attr("class","prev"); $("#nextID").attr("href","#directions"); $("#prevID").attr("href","#directions"); }else if(target=="#contact"){ $("#prevID").attr("class","prev"); $("#nextID").attr("class",""); $("#nextID").attr("href","#contact"); $("#prevID").attr("href","#contact"); }else{} $("html, body").stop().animate({ scrollLeft: $(target).offset().left, scrollTop: $(target).offset().top }, 1200); });//closing 2 $(".next").bind("click",function(event){//3 event.preventDefault(); target = $(this).attr("href"); if(target=='#home'){ a='#newsletter'; $(".next").attr("href","#newsletter"); $("#prevID").attr("class","prev"); $("#prevID").attr("href","#newsletter"); }else if(target=='#newsletter'){ a='#directions'; $(".next").attr("href","#directions"); $("#prevID").attr("href","#directions"); }else if(target=='#directions'){ a='#contact'; $(".next").attr("href","#contact"); $("#prevID").attr("href","#contact"); $(".next").attr("class",""); }else{} $("html, body").stop().animate({ scrollLeft: $(a).offset().left, scrollTop: $(a).offset().top }, 1200); // $(".next").attr("href","#"); });//closing 3 $("#prevID").bind("click",function(event){//3 event.preventDefault(); target = $(this).attr("href"); if(target=='#newsletter'){ a='#home'; $("#prevID").attr("href","#home"); $(".next").attr("href","#home"); $("#prevID").attr("class",""); }else if(target=='#directions'){ a='#newsletter'; $("#prevID").attr("href","#newsletter"); $(".next").attr("href","#newsletter"); }else if(target=='#contact'){ a='#directions'; $("#prevID").attr("href","#directions"); $("#nextID").attr("class","next"); $("#nextID").attr("href","#directions"); }else{} $("html, body").stop().animate({ scrollLeft: $(a).offset().left, scrollTop: $(a).offset().top }, 1200); // $(".next").attr("href","#"); });//closing 3 }); </code></pre> <hr> <p>It looks kinda hustle to look at. Also, Im still learnng jquery so my apologies for the unconventional syntaxes. :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload