473,387 Members | 1,504 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,387 software developers and data experts.

tag id name

GTi
I have several <div id='DivNumber1'> on my page.
the Id can be a random number between 1 and 65535.

I need a script where I can get all div tags and check if the ID is
DivNumber.

This does not work:
if(document.getElementById)
{
var ar = document.getElementsByTagName("DIV");
for (var i=0; i<ar.length; i++)
{
s1 = new String(ar[i].id);
if(s1.search('GroupItem')>=0) ar[i].style.display = "none";
}
}

Dec 13 '05 #1
11 6991
GTi
Whops: Bugfix:

if(document.getElementById)
{
var ar = document.getElementsByTagName("DIV");
for (var i=0; i<ar.length; i++)
{
s1 = new String(ar[i].id);
if(s1.search('DivNumber')>=0) ar[i].style.display = "none";
}
}

Dec 13 '05 #2
GTi wrote on 13 dec 2005 in comp.lang.javascript:
Whops: Bugfix:

if(document.getElementById)
{
var ar = document.getElementsByTagName("DIV");
for (var i=0; i<ar.length; i++)
{
s1 = new String(ar[i].id);
if(s1.search('DivNumber')>=0) ar[i].style.display = "none";
}
}


Simplified:

if(document.getElementsByTagName) {
var ar = document.getElementsByTagName("DIV");
for (var i=0; i<ar.length; i++)
if (/DivNumber/.test(ar[i].id))
ar[i].style.display = "none";
}

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Dec 13 '05 #3
GTi
Evertjan,

what does / is syntax for:
/DivNumber/.test()
in
if (/DivNumber/.test(ar[i].id))
???

Dec 13 '05 #4
GTi wrote on 13 dec 2005 in comp.lang.javascript:
Evertjan,

what does / is syntax for:
/DivNumber/.test()
in
if (/DivNumber/.test(ar[i].id))


/DivNumber/ is a regular expression.
regex test tests the string and returns true or false.
You don't need to setup an object here.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Dec 13 '05 #5
GTi wrote:
Whops: Bugfix:
Not really.
if(document.getElementById)
{
var ar = document.getElementsByTagName("DIV");
Although both methods are defined in the same DOM Level, support
for Document::getElementById() does not imply support for
Document::getElementsByTagName() in an implementation, so you
should also feature-test the latter on run-time.

<URL:http://PointedEars.de/scripts/test/whatami>, § 2.
for (var i=0; i<ar.length; i++)
Instead

for (var i = ar.length; i--;)

since order does not matter; if it does matter, use

for (var i = 0, len = ar.length; i < len; i++)
{
s1 = new String(ar[i].id);
Java != JavaScript. You do not need to create a String object in order
to work with string values or to apply properties of String.prototype.
For type conversion to string, use the String(noString) function or
the toString(noString).method. And since the value of the `id'
attribute/property already is a string, there is no type conversion
necessary.
if (s1.search('DivNumber')>=0) ar[i].style.display = "none";
Instead:

var o = ar[i];
if (o.id.indexOf('DivNumber') >= 0)
{
if (typeof o.style != "undefined"
&& typeof o.style.display != "undefined")
{
o.style.display = "none";
}
}
}

HTH

PointedEars
Dec 13 '05 #6
GTi
I have a menu structure with several <div id=DivNumberxxxx> that is
blocks of menu groups. But I also have other <div id=whatever> sections
that I don't want to hide.
But it still don't work - it hide <div id=whatever> also :

I have this function:

function MainMenuGroupExpand(obj)
{
if(document.getElementsByTagName)
{
var el = document.getElementById(obj);
var ar =
document.getElementById("MenuGroup").getElementsBy TagName("DIV");
if(el.style.display == "none")
{
for (var i=ar.length; i--;)
{
var o = ar[i];
if (o.id.indexOf('DivNumber') == 0)
{
if((typeof o.style != "undefined") && (typeof o.style.display
!= "undefined"))
{
o.style.display = "none";
}
}
}
el.style.display = "block";
}
}
}

Dec 14 '05 #7
GTi
Yes - it does work.
It was a spelling error by me.
MenuGroup -> MenyGroup
Sorry and thanks for helping me :)

Dec 14 '05 #8
GTi wrote:
I have a menu structure with several <div id=DivNumberxxxx> that is
blocks of menu groups. But I also have other <div id=whatever> sections
that I don't want to hide.
But it still don't work - it hide <div id=whatever> also :

I have this function:

function MainMenuGroupExpand(obj)
{
if(document.getElementsByTagName) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ {
var el = document.getElementById(obj); ^^^^^^^^^^^^^^^^^^^^^^^^ var ar =
document.getElementById("MenuGroup").getElementsBy TagName("DIV"); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ if(el.style.display == "none")
{
for (var i=ar.length; i--;)
{
var o = ar[i];
if (o.id.indexOf('DivNumber') == 0) ^^
Have you /really/ read _and_ understood what I posted?
[...]

PointedEars
Dec 14 '05 #9
GTi
Hmm...
Looks like I have overlooked something here.
Yes I have readed it but I admit that I do not understand it 100%
if (o.id.indexOf('DivNumber') == 0)

It is always the beginning of the tag name. It will ignore
id='otherDivNumer'

I must try to understand what the other 'red markers' are.

Dec 14 '05 #10
GTi wrote:
> if (o.id.indexOf('DivNumber') == 0) It is always the beginning of the tag name.


You mean the attribute value.
It will ignore id='otherDivNumer'
Then this line is OK so.
I must try to understand what the other 'red markers' are.


In case of questions, do not hesitate to ask.

But please learn how to quote on Usenet before:
<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
PointedEars
Dec 14 '05 #11
On 2005-12-13, GTi <tu****@gmail.com> wrote:
I have several <div id='DivNumber1'> on my page.
the Id can be a random number between 1 and 65535.

I need a script where I can get all div tags and check if the ID is
DivNumber.

var ar = document.getElementsByTagName("DIV");


how about this?

var ar = document.getElementsByTagName("div");

--

Bye.
Jasen
Dec 14 '05 #12

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

Similar topics

23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
2
by: Ravi | last post by:
My XML looks like: <abc> <def type="apple"> 1 </def> <def type="peach"> 2 </def> <def type="orange"> 3 </def> <def type="banana"> 4 </def> <def type="plum"> 5 </def> </abc>
1
by: discomiller | last post by:
Mario Mueller: Hello *, radiobuttons belong to other radiobuttons by the "name="any_value"" attribut. Thats a fakt. I got the following XML:...
21
by: TheKeith | last post by:
I heard that the name attribute is deprecated in html 4.01 strict. Is it recommended that you use the ID attribute for images along with the getElementById method instead of the old way? Thanks.
12
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" ...
11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
3
by: jparulan | last post by:
Hi All, I'm using SOAP3.0. I was able to successfully call a WSDL file and get a value properly. But when the WSDL changed to have a MULTIPLE <element name> it was failing. This code works...
1
by: ivanet | last post by:
Hello everyone, I am trying to use the following Schema but I get the error "src- resolve: Cannot resolve the name 'ValuesList' to a(n) 'element declaration' component." at line 144. I have...
2
by: pythonnewb | last post by:
I am fairly new to programming but have some very basic Java background. I am just learning python and tried to make a module that would allow me to create a file containing an address book. I was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.