Lucia
Lucia

Reputation: 614

Get tag a id inside listitem id

I'm quite to new to JQueryMobile, JavaScript and HTML. In my screen I have a list of elements that are creates dynamically and when you click on each element it should get you to another screen depending on the name of the list item you clicked.

I have tried to get the a tag id, value, name... but it doesn't work... here is my code for each line:

<li style='height:30px;' id='$object'>
    <a class='resume' id='$object' href='javascript:loadGraph(this);'>
        <span class='name' style='font-size:10pt;height:5px;' value='$object'>$object </span>
        <span class='data' style='background:$alarmColor;font-size:10pt;color:$alarmText;height:15px;'>$debitPrevMax</span>
    </a>
    <a class='info' id='$object' href='javascript:threshold(this)'>Alarm Info</a>
</li>

The list have split buttons.

Upvotes: 0

Views: 106

Answers (1)

user1106925
user1106925

Reputation:

"When I tried to access to element.id I get undefined"

When you do this...

href='javascript:threshold(this)'

...this is not a reference to the element. That's why the id is undefined.

You'd need to use onclick= instead.

onclick=':threshold(this)'

Also, as I stated in the comment above, you can not have duplicated IDs on a page. You'll likely only be able to fetch the first.

Even if you're not using them for DOM selection, it still isn't a good idea to have duplicates.

Upvotes: 2

Related Questions