You can use the querySelector for that:
document.querySelector('[id^="poll-"]').id;
The selector means: get an element where the attribute [id]
begins with the string "poll-"
.
^
matches the start
*
matches any position
$
matches the end
jsfiddle
More Related Contents:
- Do DOM tree elements with IDs become global properties?
- How to access a DOM element in React? What is the equilvalent of document.getElementById() in React
- How to getElementByClass instead of GetElementById with JavaScript?
- Why don’t we just use element IDs as identifiers in JavaScript?
- How to pick element inside iframe using document.getElementById
- document.all vs. document.getElementById
- getElementById returns null? [closed]
- Cannot read property ‘addEventListener’ of null
- getElementById() returns null even though the element exists [duplicate]
- Getting the parent div of element
- JavaScript getElementByID() not working [duplicate]
- Javascript can’t find element by id? [duplicate]
- Selecting an element in iframe with jQuery
- How to use getElementsByClassName in javascript-function? [duplicate]
- chaining getElementById
- Get element inside element by class and ID – JavaScript
- Getting element by a custom attribute using JavaScript
- “getElementById not a function” when trying to parse an AJAX response?
- Javascript Append Child AFTER Element
- getElementById.contentDocument error in IE
- getElementById returning value only for first element [closed]
- Mulitple Elements with the same ID
- Why is document.GetElementById returning null [duplicate]
- Can I use document.getElementById() with multiple ids?
- It says that TypeError: document.getElementById(…) is null [duplicate]
- How can I run different scripts based on time? [closed]
- Check if a value is an object in JavaScript
- Making custom right-click context menus for my web-app
- Amazon S3 direct file upload from client browser – private key disclosure
- Get query string parameters url values with jQuery / Javascript (querystring)