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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.