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> Link to comment https://forums.phpfreaks.com/topic/55613-solved-getelementsbytagnamea0-not-working-please-help/ 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); Link to comment https://forums.phpfreaks.com/topic/55613-solved-getelementsbytagnamea0-not-working-please-help/#findComment-274797 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] Link to comment https://forums.phpfreaks.com/topic/55613-solved-getelementsbytagnamea0-not-working-please-help/#findComment-274809 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"; Link to comment https://forums.phpfreaks.com/topic/55613-solved-getelementsbytagnamea0-not-working-please-help/#findComment-274818 Share on other sites More sharing options...
sayedsohail Posted June 14, 2007 Author Share Posted June 14, 2007 thanks corona4456 Link to comment https://forums.phpfreaks.com/topic/55613-solved-getelementsbytagnamea0-not-working-please-help/#findComment-274960 Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 No problem Link to comment https://forums.phpfreaks.com/topic/55613-solved-getelementsbytagnamea0-not-working-please-help/#findComment-274964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.