...

View Full Version : css java script extension --> event selectors



BubikolRamios
02-10-2007, 06:38 AM
googled to this site:

http://encytemedia.com/event-selectors

excelent idea, unfortunately doest't work wery well + if it works (in some cases) on FF, does not on IE. Didn't go into depth of it, anyway.

1.it realy works, but I can't figure it out ....
example that don't work(gets applied only to first div):


<DIV id="features">
a
</DIV>

<DIV id="features">
b
</DIV>

var Rules = {
........

'#features': function(element) {
//MC TEST
element.style.background = 'red';
},

.......


2. looking for javascript source with same functionality .....

thanks for tips.

liorean
02-10-2007, 06:47 AM
An id attribute MUST be unique within a page - having two elements with the same id attribute value is invalid, and behaviour of anything that operates on id attributes is undefined if there is more than one in the document. In other words, the script works perfectly fine on this point, it's the document that is broken.

BubikolRamios
02-10-2007, 08:01 AM
well, I was having this in mind:



<style type="text/css">
#tralala
{
background:red;
}
</style>


<DIV id="tralala">
a
</DIV>

<DIV id="tralala">
b
</DIV>



this works for both DIV-s. Which is then wrong ?
I presumed that java script from given link is trying to do that.

Regards

liorean
02-10-2007, 08:28 AM
/snip/
this works for both DIV-s.No. It works in *the browsers you have tried* for both divs. A browser would not be doing anything wrong if it worked only for one of them, and it could be either one.
Which is then wrong?The HTML for that page is, as I explained invalid. Because of how the CSS engine works, it makes sense to deal with it that way. But it's not the ONLY way to do it.
I presumed that java script from given link is trying to do that.Well, JavaScript (or more exactly, the DOM) deals with it in a different way than CSS, for reasons way too technical for me to talk about in a forum post. And browsers do NOT behave the same with regards to ids and the DOM.


Anyway, the point I was making is: Fix the page, and the script will work. The page is broken but the script doesn't do anything wrong. It assumes that since it's an id attribute, there won't be more than one matching element. And that is an assumption it's entirely correct in making.

BubikolRamios
02-10-2007, 09:21 AM
thanks for pointing that out. Learned the stuff wrong from many wrong examples (-:

Linked the stuff to class. Works like a charm, for now (-:

before


'#features': function(element) {....


after


'.features': function(element) { ...


Regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum