Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery if then else using URL parser plugin, there must be a more elegant solution!
    primarykey
    data
    text
    <p>This is my first post on this rather spiffing website so go easy on me if this has been discussed elsewhere (I can't find it if it has).</p> <p>I'm using the JQuery URL parser plugin found here: <a href="http://projects.allmarkedup.com/jquery_url_parser/" rel="nofollow noreferrer">http://projects.allmarkedup.com/jquery_url_parser/</a></p> <p>I can get it to do what I want but the code is rather inefficient. I have a collection of hidden div's that are opened when the relevant heading is clicked. I am using the URL parser so that if a link is clicked from another page the relevant div is visible.</p> <p>My code looks like this:</p> <pre><code>if (jQuery.url.attr('anchor') == 'question1'){ $('#answer1').show(); } else if (jQuery.url.attr('anchor') == 'question2'){ $('#answer2').show(); } else if (jQuery.url.attr('anchor') == 'question3'){ $('#answer3').show(); } else if (jQuery.url.attr('anchor') == 'question4'){ $('#answer4').show(); } else if (jQuery.url.attr('anchor') == 'question5'){ $('#answer5').show(); } else if (jQuery.url.attr('anchor') == 'question6'){ $('#answer6').show(); } else if (jQuery.url.attr('anchor') == 'question7'){ $('#answer7').show(); } else if (jQuery.url.attr('anchor') == 'question8'){ $('#answer8').show(); }; </code></pre> <p>As you can see this is rather long winded. What I really want to be able to do is take the number at the end of the URL and append it to #answer so that things are far more compact. I was trying to assign the result of (jQuery.url.attr('anchor') to a variable but I'm having a bit of trouble accomplishing this. Any help would be greatly appreciated!</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