Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ID of dom-element

Tags:

javascript

console.log(video);

puts in my console the following line:

<object type=​"application/​x-shockwave-flash" class=​"video" data=​"http:​/​/​www.youtube.com/​v/​vyFAF-J3jzM" width=​"308" height=​"100" id=​"video" style=​"visibility:​ visible;​ ">​…​</object> 

So "video" holds the entire dom-object. How can I query the ID of this object with JavaScript?

Something like var vidID = video.getId();

like image 769
matt Avatar asked Feb 16 '11 22:02

matt


People also ask

How do I get the DOM element value?

One of the most common methods to access an element in HTML DOM is getElementById() which accesses an element based on the value of its ID attribute. The value of the ID attributes are supposed to be unique and no two elements on a single HTML page should have similar IDs.

How can I get the ID of an element using JavaScript?

getElementById() is a quick way to access an element. Unlike the querySelector() method, the getElementById() is only available on the document object, not other elements. In this syntax, the id is a string that represents the id of the element to select. The id is case-sensitive.

What is ID and name in DOM?

id= labels the fields for use by JavaScript and Java DOM (Document Object Model). The names in name= must be unique within a form. The names in id= must be unique within the entire document.


2 Answers

It's simply video.id ........

like image 122
jondavidjohn Avatar answered Sep 26 '22 00:09

jondavidjohn


var videoElement = document.getElementById('video'); var idOfElement = videoElement.getAttribute('id'); 
like image 31
The Scrum Meister Avatar answered Sep 23 '22 00:09

The Scrum Meister