Reputation: 11
I'm trying to use a Chrome bookmarklet to grab data off of a site for work. I do not have access to modify the code of the site.
This is an example of a field I'm trying to grab:
<div style="width:100%; height:100%;" bindonce="" class="ng-scope">
<de-field-label>
<div class="pull-left ng-scope" style="width: 100%">
<label class="pull-left">Last Name</label>
</div>
</de-field-label>
<input class="tt-input ng-scope"
bo-class="{'tt-agency-required': field.agencyValidation === 1}"
de-cascade=""
ng-disabled="true"
de-input-mask=""
de-text-box=""
sectionid="0b340920-8989-ce72-7bb4-08d51598a6d9-0"
id="Victims_0b340920-8989-ce72-7bb4-08d51598a6d9_0_lastName"
disabled="disabled">
</div>
The id is dyamically generated
Upvotes: 0
Views: 77
Reputation: 10328
If I have not misunderstood the ID is always different so you have to use something else to identify the input and then go and read the ID I will try with:
var input = document.getElementsByClassName("tt-input").item(0);
var id = input.id
Upvotes: 0
Reputation: 943615
Since you don't know what the ID will be, getElementById
is useless to you.
Find something else about the element that uniquely identifies it, such as a class, or a data-*
attribute, or it's relationship in the DOM with an element that you do know the ID of. In short, anything you could express with a selector.
Then use that as an argument to querySelector
.
Upvotes: 0
Reputation: 100351
You can use the attribute selector to check if the id starts with something
document.querySelector('[id^=Victims_]')
or ends with something
document.querySelector('[id$=lastName]')
Upvotes: 4