Click to See Complete Forum and Search --> : Getting the ID name
I'm not sure if this can be done but what I want to do is compair the value I gave a div's id, with a variable. For instance, if I have the following tag,
<div id="test"> can I compair "test" with a variable I named earlier, something like this,
var testvar = "test";
if (testvar == "nameofidtag")
{
code here
}
Can this be done?? Note: if it can be done with name, etc. that should work for me as well. I tried the getElementsById, but that didn't seem to work. :(
Ok, I'm not sure what you mean by your last post. I don't think it is what I want, though.
Here's what I'm trying to do.
I'm working on a menu, and what I want to do is compair the id of a div tag with the current location. I wrote this code to throw the current location in the nam variable:
pageURL = top.location.href;
array = pageURL.split ('/');
name = array[array.length-1];
So, what I want to do is compair name with the value of a div id.
<div id="home.htm" ...>
What it will do is let me know which menu item corresponds to their current location. Make sence?? :)
This doesn't seem to be working for me. Even when I have div tags, it returns the div not found alert. Any idea why that would be?
Here's what it did... it returned a 3 for the first alert (the same as my number of div tags), the value of the first div tag for the second alert, and then crashed my computer... Just kidding.. :) But seriously, my machine did crash right after I tried that, so I won't be able to get back to you for sure on this until later on tonight or early tomorrow...
Ok, I got all this working...Thanks for you help, Dave. :)
The problem:
Make a div with an ID the same as your page location (page home.htm with a div tag like so <div id="home.htm" class="...> What is does is checks for your current location, and that menu item has a differnt color scheme than the rest.
The solution:
1. Splitting URL so only characters after the last / are present.
2. Creating a function to getElementsByName ("div") and get their IDs.
3.Creating separate mouseover and mouseouts for the divs the = the page url.
Here is my finished code, if you want to take a look. You can probably understand better what I mean with an example. :D
It is a possiblility...I don't have that code anymore, so I can't check, but it is possible that I didn't name the div correctly.