Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The onclick attribute is an event handler attribute is the same as what you are doing in this line of code on your script:</p> <p>$("ol.tabs li").click(</p> <p>See: <a href="http://reference.sitepoint.com/html/event-attributes/onclick" rel="nofollow">http://reference.sitepoint.com/html/event-attributes/onclick</a></p> <p>In other words you are assigning the handling of the click event to a script by the name of '#tab1' The hash tag is an 'illegal' script char.</p> <p>To accomplish what you want there are a few thinks you can do. First use a data attribute.</p> <pre><code>&lt;ol class="tabs"&gt; &lt;li&gt;&lt;a data-tab-name="#tab1"&gt;Unique benefits&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a data-tab-name="#tab2"&gt;Insurance&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a data-tab-name="#tab3"&gt;Business Loan&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt; </code></pre> <p>And them change your js line to:</p> <pre><code>var activeTab = $(this).find("a").attr("data-tab-name"); </code></pre> <p>On a related note I will change a few more things on your script. Since you are attaching the event handler to the onclick event of the list item I will add the attribute to the list item as follow.</p> <pre><code>&lt;ol class="tabs"&gt; &lt;li data-tab-name="#tab1"&gt;&lt;a&gt;Unique benefits&lt;/a&gt;&lt;/li&gt; &lt;li data-tab-name="#tab2"&gt;&lt;a&gt;Insurance&lt;/a&gt;&lt;/li&gt; &lt;li data-tab-name="#tab3"&gt;&lt;a&gt;Business Loan&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt; </code></pre> <p>That allows me to cahnge the js line to this:</p> <pre><code>var activeTab = $(this).attr("data-tab-name"); </code></pre> <p>What should improve performance a bit but more important makes the code more readable.</p> <p>Hope this helps.</p>
 

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