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

change the ID dynamically

hello there.....
i have a problem here...........i want to assign ID attribute
dynamically to the html tags......and i need a function for tht....can
anybody help me out in tht

May 31 '06 #1
6 47656
ma***********@gmail.com wrote:
i have a problem here...........i want to assign ID attribute
dynamically to the html tags......and i need a function for tht....can
anybody help me out in tht


That is as impossible as your posting "style".

<URL:http://jibbering.com/faq/>
PointedEars
--
There are two possibilities: Either we are alone in the
universe or we are not. Both are equally terrifying.
-- Arthur C. Clarke
May 31 '06 #2
Thomas 'PointedEars' Lahn wrote:
ma***********@gmail.com wrote:
i have a problem here...........i want to assign ID attribute
dynamically to the html tags......and i need a function for tht....can
anybody help me out in tht


That is as impossible as your posting "style".


Why would that be impossible ?

<html>
<body>
<p>content</p>
<script language="javascript" type="text/javascript">
document.getElementsByTagName('p')[0].setAttribute('id','myID');
alert(document.getElementById('myID').innerHTML);
</script>
</body>
</html>

--
Bart

May 31 '06 #3
Bart Van der Donck wrote:
Thomas 'PointedEars' Lahn wrote:
ma***********@gmail.com wrote:
> [assign ID attribute dynamically to the html tags]
That is as impossible as your posting "style".


Why would that be impossible ?

<html>
<body>
<p>content</p>
<script language="javascript" type="text/javascript">


The `language' attribute is deprecated long since, and your markup
is not Valid; especially, the missing DOCTYPE declaration triggers
Quirks Mode, which can change DOM behavior.
document.getElementsByTagName('p')[0].setAttribute('id','myID');
alert(document.getElementById('myID').innerHTML);
</script>
</body>
</html>


That is setting the attribute, not changing it. Note the Subject header.
Furthermore:

- This requires other DOM methods that may not be available.

- It is known to be not possible for some elements in some DOMs
(IIRC there are issues in the IE DOM).

- setAttribute() implementations are known to be buggy.
PointedEars
--
In the First World War, 13 million people were killed. In the Second
World War, 40 million people were killed. I think that if a third war
takes place, nothing is going to be left on the face of earth.
-- Shakira, 2003-02-05 @ MTV.com
May 31 '06 #4
Thomas 'PointedEars' Lahn said the following on 5/31/2006 8:26 AM:
Bart Van der Donck wrote:
Thomas 'PointedEars' Lahn wrote:
ma***********@gmail.com wrote:
[assign ID attribute dynamically to the html tags]
That is as impossible as your posting "style". Why would that be impossible ?

<html>
<body>
<p>content</p>
<script language="javascript" type="text/javascript">


The `language' attribute is deprecated long since, and your markup
is not Valid;


Semi-valid point but irrelevant to the rebuttal to your assertion that
it was impossible.
especially, the missing DOCTYPE declaration triggers Quirks Mode,
which can change DOM behavior.
Only in IE and in this case it makes no difference.
document.getElementsByTagName('p')[0].setAttribute('id','myID');
document.getElementById('p')[0].id = 'newID';
alert(document.getElementById('myID').innerHTML);
</script>
</body>
</html>
That is setting the attribute, not changing it. Note the Subject header.


Yoohoo, dimwit, think about it. An element has an ID. You "set" the ID,
then alert that elements ID. It will give you the new ID. That is
changing the ID. You can be as pedantic as you want but the ID got changed.
Furthermore:

- This requires other DOM methods that may not be available.
Only if the user is using an antiquated anti-social browser.
- It is known to be not possible for some elements in some DOMs
(IIRC there are issues in the IE DOM).
Such as?
- setAttribute() implementations are known to be buggy.


Then you offer a better alternative. Or, preferably, you STFU and move on.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 31 '06 #5
Thomas 'PointedEars' Lahn wrote:
Bart Van der Donck wrote:
Thomas 'PointedEars' Lahn wrote:
ma***********@gmail.com wrote:
> [assign ID attribute dynamically to the html tags]

That is as impossible as your posting "style".


Why would that be impossible ?

<html>
<body>
<p>content</p>
<script language="javascript" type="text/javascript">


The `language' attribute is deprecated long since, and your markup
is not Valid; especially, the missing DOCTYPE declaration triggers
Quirks Mode, which can change DOM behavior.
document.getElementsByTagName('p')[0].setAttribute('id','myID');
alert(document.getElementById('myID').innerHTML);
</script>
</body>
</html>


That is setting the attribute, not changing it. Note the Subject header.
Furthermore:

- This requires other DOM methods that may not be available.

- It is known to be not possible for some elements in some DOMs
(IIRC there are issues in the IE DOM).

- setAttribute() implementations are known to be buggy.


Hmmmm, that Asperger-smell in the morning :-)

--
Bart

May 31 '06 #6
You can assign an id to any element simply by saying:

El.id = "foo";

If, for instance, you wanted to assign an ID to every FORM tag on the
page, you could do:

for(var i=0; i<document.forms.length; i++) {
document.forms[i].id = "formtag_" + i;
}

If you had three FORM tags on your page and you ran that loop, the form
tags would have ids "formtag_0", "formtag_1", "formtag_2".

Exactly how you will iterate over the tags you want to assign IDs to
will depend on exactly which tags you need to work with.

ma***********@gmail.com wrote:
hello there.....
i have a problem here...........i want to assign ID attribute
dynamically to the html tags......and i need a function for tht....can
anybody help me out in tht


Jun 1 '06 #7

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

Similar topics

7
by: juglesh | last post by:
Hello, I would like to be able to have the user sort a list of items similarly to the way you sort your queue on Netflix.com. (the numbers dont change dynamically on netflix, they must be doing...
2
by: puunda | last post by:
Hi All, I had previously asked this question with regard to Cyrstal Reports, which I believe is not the most suitable for doing the job. The problem: I need to create a report with X number...
3
by: jpatterson | last post by:
Hi, I need to be pointed in the right direction. I'm looking for a way to dynamically change a table in a query. I have a table called students and each fiscal year the student table will get...
3
by: Quentin | last post by:
Hey there ! I made my own WebControl, that inherits from WebControls, and i added an HtmlTable to it. I would like to include a file, dynamically, to one of its cells... I've already searched,...
37
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use)....
3
by: DMA | last post by:
Hello, How can I change my IP address ? I try to do it in C#. It's easy to get the IP but to fix it is another problem.. Sincerely David M.
5
by: marfi95 | last post by:
I have a form that has a left and right panel. In the left panel is a treeview. The right panel I want to change dynamically based on the type of node selected. What I'm doing is loading the...
1
by: difah | last post by:
Hello, I'am currently designing a reportviewer, and what i want to do is when the user click on a image, this image change. I know how to change dynamically the image on load but not on click. ...
2
missshaikh
by: missshaikh | last post by:
hi friends I am programming a website which will include ad banners. The requirements are that the banners will be dynamically changing for each page. By this I mean that if there are ten...
0
by: panindra | last post by:
hi im newbie to flex.. im using itemrenderer in a list to use a Hbox.. n Hbox contains a image,label and button,...i v to change a particular row of a list... To be more precise,i v to change the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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...

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.