473,396 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

(simple?) DOM problem

I have a simple DHTML gallery:

<script>
viewPhoto(thumb){
function viewPhoto(thumb){
document.getElementById('mainPhoto').src=thumb.hre f;
return false;
}
</script>

....
<body>
<a onclick="javascript:return viewPhoto(this);" href="whatever"><img src="thumbnail" /></a>
</body>
....
I want the currently viewed images' thumbnail to have a nice thick red-border.
I have managed to do this slap dash, but I had a better way, My only problem is
that I need to find out the DOM Array value of the thumbnail object (ie the "thumb" param)
Is this possible?
Feb 8 '06 #1
4 1310
bmgz said the following on 2/8/2006 6:16 AM:
I have a simple DHTML gallery:
No, that's not a "DHTML gallery", it is a simple image swap routine.
<script>
<script type="text/javascript">
viewPhoto(thumb){
That is a good example of why people shouldn't try to type/paste
snippets into a post. I have to assume that was an errant mis snip.

function viewPhoto(thumb){
document.getElementById('mainPhoto').src=thumb.hre f;
document.images['imageNAME'].src = thumb.href;

Now, it is more cross-browser friendly.
return false;
}
</script>

....
<body>
<a onclick="javascript:return viewPhoto(this);" href="whatever"><img
no need for the javascript: label, drop it.
src="thumbnail" /></a>
</body>
....
I want the currently viewed images' thumbnail to have a nice thick
red-border.
Then give it one. That is what CSS is for:

<img ...... name="mainPhoto" style="border: solid 20EM red">

How thick do you want it?
I have managed to do this slap dash, but I had a better way
What in the world is a "slap dash"?
My only problem is that I need to find out the DOM Array value of
the thumbnail object (ie the "thumb" param)
Nothing in that sentence makes any sense at all.

What is a "DOM Array value"?
Is this possible?


Nobody can answer that until you explain what it is you are trying to do.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 8 '06 #2
I tried to simplify the the code, but I ended up making a hash of things,
It is DHTML because I brought CSS into the mix (not visible in my pityful earlier post)
I can code but my jargon sux like **** (I don't converse verbally with other coders..)
anyways here goes:

function viewPhoto(thumb){
document.getElementById('mainPhoto').src=thumb.hre f;
thumbs = document.getElementById('property-thumbnail-browser').getElementsByTagName('img');
for(i=0; i<thumbs.length; i++){
thumbs[i].className="thumbnail-normal";
}
thumb.firstChild.className="thumbnail-current";
return false;
}

I want to neaten this code by changing the loop logic to:

function viewPhoto(thumb){
document.getElementById('mainPhoto').src=thumb.hre f;
thumbs = document.getElementById('property-thumbnail-browser').getElementsByTagName('img');
for(i=0; i<thumbs.length; i++){
< If this is the image i clicked on > <-- I need to find the Index of the object???
thumb.firstChild.className="thumbnail-current";
< Else >
thumbs[i].className="thumbnail-normal";
}

return false;
}

I know this looks crude because the firstChild etc. relies implicitly on my markup being precise,
but it works for me... Another wierd thing I noticed was Firefox treating a literal space ' ' in
your markup as a Node?
Feb 8 '06 #3
bmgz wrote:
I can code but my jargon sux like **** (I don't converse verbally with
other coders..)


converse? sorry it's been a long day ;(
Feb 8 '06 #4
bmgz wrote on 08 feb 2006 in comp.lang.javascript:
function viewPhoto(thumb){
document.getElementById('mainPhoto').src=thumb.hre f;
thumbs =
document.getElementById('property-thumbnail-browser').getElementsB
yTagName('img'); for(i=0; i<thumbs.length; i++){
< If this is the image i clicked on > <-- I need to find the
Index of the object???
thumb.firstChild.className="thumbnail-current";
< Else >
thumbs[i].className="thumbnail-normal";
}

return false;
}


var which = false;

function viewPhoto(thumb){
document.getElementById('mainPhoto').src = thumb.src;
if (which)
which.firstChild.className = "thumbnail-normal";
thumb.firstChild.className="thumbnail-current";
which = thumb;
return false;
}
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
0
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
18
by: Sender | last post by:
Yesterday there was a very long thread on this query. (You can search on this by post by 'sender' with subject 'Simple Problem' post date Oct 7 time 1:43p) And in the end the following code was...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.