Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting an <li> element as "active" on onload
    primarykey
    data
    text
    <p>I am making a fly-out menu with 11 items that can be moused over on the left and a content box to the right. On mouseover it works fine but I want the first element "Overview" to be set as 'active' on page load giving the users a description of what the other elements are. I have tried sticking "onload="document.getElementById('switch1').focus();"" in an inline for the desired li tag, earlier in the Javascript, and inline in the body tag to no avail. Perhaps I am not adding it properly? Are there better solutions to getting that element highlighted? Any help would be amazing! Thank you in advance.</p> <pre><code>function init() { document.getElementById('switch1').focus(); } window.onload = init; $(document).ready(function() { switches = $('#switches &gt; li'); slides = $('#slides &gt; div'); switches.each(function(idx) { $(this).data('slide', slides.eq(idx)); }).hover( function() { switches.removeClass('active'); slides.removeClass('active'); $(this).addClass('active'); $(this).data('slide').addClass('active'); }); }); .4Column{ width: 250px; height: 239px; float:left; margin-left:30px;} #switches .hover { background-position: left center; display: block;} #switches .active { font-weight: bold; background-position:left bottom;} #switches li { padding-left:10px; background-image:url(../images/ManageArrows.jpg); background-repeat:no-repeat; height:20px; width:230px;} #slides div { display: none;} #slides div.active { display: block;} .IndySlide{ width: 336px; height: 255px; float:left; background-color:#FFF;} #switch1{ padding-left:10px; background-image:url(../images/ManageArrows.jpg); background-repeat:no-repeat; width: 230px; height: 20px;} #switch1 .active{ font-weight: bold; background-position:left bottom;} &lt;div class="4Column" style="width:250px; height:239px; float:left; margin-left:0px;"&gt; &lt;div id="featured"&gt; &lt;ul id="switches" class="active"&gt; &lt;li id="switch1"&gt;Overview&lt;/li&gt; &lt;li id="switch2"&gt;Agriculture&lt;/li&gt; &lt;li id="switch3"&gt;Forests&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="4Column" style="width:335px; height:255px; float:left; margin-left:20px;"&gt; &lt;div id="slides"&gt; &lt;div class="IndySlide"&gt;&lt;!-- Overview --&gt; &lt;p&gt;This is a list of the most amazingestest links on the DNR baby sites.&lt;/p&gt; &lt;/div&gt; &lt;div class="IndySlide" style="background-image:url(images/cowbg.png);"&gt;&lt;!-- Agriculture --&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://dnr.alaska.gov/ag/ag_calendar_2012.htm"&gt;Ag event calendar&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dnr.alaska.gov/ag/ag_bac.htm"&gt;Ag board meetings&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div style="background-image:url(images/forestrybg.png);width:336px; height:255px;"&gt;&lt;!-- Forests --&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://forestry.alaska.gov/stateforests.htm"&gt;State Forests&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://forestry.alaska.gov/burn/"&gt;Burn permits&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://forestry.alaska.gov/fire/current.htm"&gt;Fire information&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    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.
    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