RobinHo
RobinHo

Reputation: 575

get the value of the current ID in an list item

can any of you pls tell me how to get the value of the current ID out of this list item. I have many list items which are generated by java servlets so I need to get the current ID of the list (which is clicked):

so when i click:

$('li.doBlokkeer').hover(function(e) {

now I need the value of the id

<li class="doBlokkeer" id="${cell.id}"></li>

I think it is something like, but it doesnt work

  var idblokkeer = document.getElementById('doBlokkeer');
  var valueid = idblokkeer.getAttribute('id');

Upvotes: 0

Views: 439

Answers (2)

Suresh Atta
Suresh Atta

Reputation: 121998

Try to get with using this

$('li.doBlokkeer').hover(function (e) {
    alert($(this).attr("id"));
});

Where this is the current element you hovered.

http://learn.jquery.com/javascript-101/this-keyword/

Have a demo

Upvotes: 3

halkujabra
halkujabra

Reputation: 2942

Change this -

var idblokkeer = document.getElementById('doBlokkeer');
  var valueid = idblokkeer.getAttribute('id');

to this-

var idblokkeer = document.getElementsByClassName[0]('doBlokkeer');
  var valueid = idblokkeer.getAttribute('id');

Upvotes: -1

Related Questions