Where to store a "variable" in a <div>?

A

Akbar

All,

I'm currently using an alt attribute in a div tag to store "keywords"
for a function that will show or hide certain div's based on a given
keyword. Is there a better (standard) place to put these keywords?

Code can be seen at http://www.straffin.com/test/DUdyn2.html . This is
just a sample... the real "keywords" (and other information) will be
pulled out of an XML file, not programatically generated.

- Akbar
 
L

Lasse Reichstein Nielsen

Akbar said:
I'm currently using an alt attribute in a div tag to store "keywords"
for a function that will show or hide certain div's based on a given
keyword. Is there a better (standard) place to put these keywords?

That sounds like a job for "class". The class attribute value is a
space-separated list of "class" names, and it is meant to distinguish
equivalent elements based on the author's intentions.

/L
 
A

Akbar

That sounds like a job for "class". The class attribute value is a
space-separated list of "class" names, and it is meant to distinguish
equivalent elements based on the author's intentions.

/L

I've used "class" to assign CSS styles before... you also mean to tell
me that you can assign multiple CSS styles with multiple classes?

<style>
.red { color : Red; }
.bold { font-weight : bold; }
</style>
<p class="red bold">Wow!</p>

(I just tried it... it works, in IE6 anyway.) Wow! Thanks!

- Akbar
 
L

Lasse Reichstein Nielsen

Akbar said:
I've used "class" to assign CSS styles before... you also mean to tell
me that you can assign multiple CSS styles with multiple classes?

In a CSS 1 compliant browser, yes. Older browsers, like Netscape 4,
have no support for CSS 2 (except where it matches CSS 1, and then
it's still bad).
(I just tried it... it works, in IE6 anyway.) Wow! Thanks!

I wasn't sure it would work in IE6, since its CSS 2 support
is also seriously lacking. Glad to see they have it.

It should work in Mozilla and Opera, and probably most other
recent browsers.

/L
 
C

Code Ronin

Akbar said:
Is there a better (standard) place to put these keywords?

No, I do not believe so. In fact, you are using "alt", which does have
a standard usage and might cause side effects.

The beauty of JavaScript is that you can dynamically add properties to
any object, including HTML elements. You are not limited to the
"published" attributes. (I do not believe you should use the published
attributes, in fact, as your purpose does not match any of theirs.)

Here are the lines I changed in your JavaScript in order to get the
same effect (under IE6SP1, you will have to test the other browsers
you support):

1. Move the line [ var re = new RegExp(m, "g"); // Set up the match ]
out of the for-loop. There is no reason to keep recreating the RegExp
object.

2. Change the line [ DOMobjDiv.alt = temptextone + " " + temptexttwo;
] to [ DOMobjDiv.keywords = temptextone + " " + temptexttwo; ]. Here,
you have simply created a new, custom attribute "keywords" for your
DIV element and assigned your keywords to it.

3. Change the line [ var result = kids.alt.match(re); // Look for
a match ] to [ var result = kids.keywords.match(re); // Look for a
match ]. Here, you are searching the custom keywords attribute, rather
than the alt attribute.

Same effect, less chance for a name clash.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,219
Latest member
Geraldine7

Latest Threads

Top