Jump to content

get element by class


Kevin McLean

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.