Kevin McLean Posted January 24, 2009 Share Posted January 24, 2009 Hi everybody. I'm a newbie in web designing so that faced a lot of problems concerning combination of css and js in developing my web page. First of all, in my css file I use classes and it does not allow me to embody my idea: I want a block with info to appear after clicking on a nick name. Javascript file which is in charge of block behaviour. <script language="JavaScript" type="text/javascript"> function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; } function show_bar(ev,nom) { MouseX = ev.clientX + document.body.scrollLeft; MouseY = ev.clientY + document.body.scrollTop; obj = document.getElementById(nom); obj.style.top = MouseY + 10-document.getElementByClass("wrap").offsetParent.offsetTop-40+"px"; obj.style.left = MouseX-document.getElementByClass("wrap").offsetParent.offsetLeft+"px"; obj.style.visibility = "visible"; }function hide_bar(nom) {document.getElementByClass(nom).style.visibility="hidden"}</script> webpage: http://gviragon.ru/study/students.php so when I click on a nickname in one of 3 tables nothing happens. The second problem, there is a gigant space after layout caused by this js, is it possible to avoid it? Could somebody help me with that? Thank you Link to comment https://forums.phpfreaks.com/topic/142272-get-element-by-class/ Share on other sites More sharing options...
Kevin McLean Posted January 25, 2009 Author Share Posted January 25, 2009 Change to <script language="JavaScript" type="text/javascript"> function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; } function show_bar(ev,nom) { MouseX = ev.clientX + document.body.scrollLeft; MouseY = ev.clientY + document.body.scrollTop; obj = document.getElementsByClass[0](nom); obj.style.top = MouseY + 10-document.getElementsByClass[0]("wrap").offsetParent.offsetTop-40+"px"; obj.style.left = MouseX-document.getElementsByClass[0]("wrap").offsetParent.offsetLeft+"px"; obj.style.visibility = "visible"; }function hide_bar(nom) {document.getElementsByClass[0](nom).style.visibility="hidden"}</script> but still nothing happens Link to comment https://forums.phpfreaks.com/topic/142272-get-element-by-class/#findComment-745894 Share on other sites More sharing options...
webster08 Posted January 25, 2009 Share Posted January 25, 2009 do a search for "getElementsByClassName" and this will help you more then anything. because it looks like you trying to adapt a script you found somewhere to your web page. Link to comment https://forums.phpfreaks.com/topic/142272-get-element-by-class/#findComment-745970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.