sayedsohail Posted June 14, 2007 Share Posted June 14, 2007 Hi everyone, I wrote function to select <a> value into the var using javascript. but it doesn't work. Here is my code. HTML <ul id="tabnavigation"> <li><a href="#">Help</a> <li><a href="#">Check</a> </ul> <script> function selectalert(acss) { if (!acss){ var pcss=document.getElementById('tabnavigation').getElementsByTagName('a')[0]; alert(pcss);} } window.onload=selectalert("") </script> Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 I'm assuming you want to get the text within the 'a' tag: alert(pcss.text); Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted June 14, 2007 Author Share Posted June 14, 2007 i just wish to define the class name for <a>[0][code] within this tabnavigation. [/code] Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 To define the class name for a tag just do the following: var pcss=document.getElementById('tabnavigation').getElementsByTagName('a')[0]; pcss.className = "whateverTheClassNameIs"; Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted June 14, 2007 Author Share Posted June 14, 2007 thanks corona4456 Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 No problem Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.