Closed Thread Icon

Preserved Topic: Access all elements associated with a certain style? Pages that link to <a href="https://ozoneasylum.com/backlink?for=18088" title="Pages that link to Preserved Topic: Access all elements associated with a certain style?" rel="nofollow" >Preserved Topic: Access all elements associated with a certain style?\

 
Author Thread
lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 07-18-2001 10:52
code:
<style>
.mystyle {border:solid 1px red;}
</style>
<html>
<body>
<form name="myform">
<span id="a1" class="mystyle">hi!</span><br>
<span id="a2" class="mystyle">hi!</span><br>
<br>
<textarea name="t" cols="40" rows="10"></textarea><br>
<input type="button" value="change" onclick="myform.t.value = changestyle();">
</form>

<script language="JavaScript">
<!--
function changestyle()
{
a = document.all;
obj = null;
str = "";
for (i=0;i<a.length;i++)
{
if (a[i].id == "a1")
{
obj= a[i];
for (x in a[i])
{
str = str + x + "\n";
} // for x
} // if
} // for i

if (obj)
{
obj.innerHTML = "<input type='text' value='"+ obj.innerText + "'>";
}
return str;
}
//-->
</script>

</body>
</html>



what is the optimal way to search for the elements that are associated with a certain style and then play/change these elements?

i tried to check for a[i].class == 'mystyle' but it failed...


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-18-2001 13:32

Oh, i definitely posted something that does that a while ago... the question is, can I find it in the archives...

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-18-2001 13:34

Here it is
http://www.ozoneasylum.com/Forum2/HTML/000730.html

Go down a few posts in it, I end up answering my own question.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 07-18-2001 13:48

No Slime! that doesn't answer my question!

I don't want to change the CSS w/ JS, instead, i want to get the list of object that reference a certain style!

again:

code:
<a id="a1" class="cl1">adsda</a>
<p id="p1" class="cl1">a112</a>
<span class="cl2">dasda</span>


I want to have an array holding reference to all elements that referenced style "cl1"
function getAllElementThatRefeered(whatstyle)
{
// do something that i can't code
return refeerersAr;
}

that if called like: ar = getAllElementThatRefeered("cl1");
'ar' will hold: a, p (with ids: a1, p1)



Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-18-2001 14:33

Hmm. That's tougher... You want an array of objects that have a certain class... there may be a way to do that, I can look into it later if no one else knows how...

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-18-2001 15:51

Well, we've done Mouseover buttons via CSS change. Dunno if this does what you're asking.....

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 07-19-2001 08:42

Pugzly, very nice one!


Actually, I believe there is only one way....same as I pasted originally: "Loop through all Elements and filter them"


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-19-2001 13:48

The question is, how to filter them. I saw recently someone mentioned a setAttribute() function. Is there a getAttribute() function? You could use getAttribute("class").

Sash
Paranoid (IV) Inmate

From: Canada, Toronto
Insane since: May 2000

posted posted 07-19-2001 13:53

Crazy, NN 4.08 doesn't even recognize the links on Pugzly's example.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-19-2001 18:07

Slime, yes there is also a getAttribute() function. Oh, and you could remember my name (since I mentioned that), I'm not "someone"...

Sash, that's because Shitscape doesn't support events on <TD> tags...

« BackwardsOnwards »

Show Forum Drop Down Menu