Topic: Using DOM to dynamically add a class to an 'a' tag (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=31485" title="Pages that link to Topic: Using DOM to  dynamically add a class to an &amp;#039;a&amp;#039; tag (Page 1 of 1)" rel="nofollow" >Topic: Using DOM to  dynamically add a class to an &#039;a&#039; tag <span class="small">(Page 1 of 1)</span>\

 
strangelybrown
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Nov 2009

IP logged posted posted 11-16-2009 19:24 Edit Quote

I am using a tabbed panel layout (JQuery) and when a tab is clicked 'class="current"' is dynamically added to the 'a' tag. The only trouble is I want to change the default 'current tab' when the page loads so I am hoping I can add 'class="current"' to the tab I require using DOM. I am very new to this so would be very grateful for any direction. I was planning on calling the Javascript code using an 'onload' event. Any help would be gratefully appreciated.

Thank you.

Blaise
Paranoid (IV) Inmate

From: London
Insane since: Jun 2003

IP logged posted posted 11-17-2009 11:11 Edit Quote

Can you not just add class="current" directly to the HTML for each given page?

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

IP logged posted posted 11-17-2009 18:10 Edit Quote

How is the default tab currently designated?
If it is defined in the jQuery code, find it and change it. If it is defined by the HTML, change the HTML...

Taeo920
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Nov 2009

IP logged posted posted 11-26-2009 06:54 Edit Quote
code:
$(document).ready(function() {
	$(".classOfYourContainer a").addClass("current");
});



That is a bit of jQuery to add a class to an element on page load. However if you're using the default jQuery tab implementation it should automatically make the first element in the tab container the current tab upon page load.

strangelybrown
Obsessive-Compulsive (I) Inmate

From:
Insane since: Nov 2009

IP logged posted posted 11-26-2009 16:35 Edit Quote

Thank you very much - I'll give it a go.



Post Reply
 
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
 
Your Text:
Loading...
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu