A way to store data in html in order to use it in js code?

D

d.adamkiewicz

Hello Folks

I would like to do some element manipulation via javascript onclick
event - changing 'background-image' property mainly. I was wondering
if it is a way to store element properties in html in order to use
them in a future?

A way I know - I could include some css classes (but name of class
must be hardcoded in javascript code). Then remove one class and add
another.

I was thinking about separation javascript code and html/css - a way
to let webmaster configure behaviour via (say config values) in html.

Regards
Darek
 
D

David Mark

Hello Folks

I would like to do some element manipulation via javascript onclick
event - changing 'background-image' property mainly. I was wondering
if it is a way to store element properties in html in order to use
them in a future?

A way I know - I could include some css classes (but name of class
must be hardcoded in javascript code). Then remove one class and add
another.

That is one way. This way makes sense if multiple elements will need
to be changed. Yes, the class names will appear in your code, but at
least the image paths will not.
I was thinking about separation javascript code and html/css - a way
to let webmaster configure behaviour via (say config values) in html.

I suspect you are considering invented attributes to hold the
background image paths and you should not do that as it will
invalidate your pages.

You might look into combining your background images and adjusting the
background position to display the appropriate section. But then the
positions are hard-coded into your script. Any way you slice it, the
script has to know how to effect the style changes and there is no
standard way for the content to advertise this information.

If you are just trying to do mouseover effects, you can manage those
with CSS alone.
 
D

dhtmlkitchen

That is one way. This way makes sense if multiple elements will need
to be changed. Yes, the class names will appear in your code, but at
least the image paths will not.
If you are just trying to do mouseover effects, you can manage those
with CSS alone.

Yes, go with CSS Sprites. You can search this.
 

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

Staff online

Members online

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top