Retrieve List item value

How should I get the value of the list item inside this function (basically when a button is clicked) :

$('.hideClass').bind('click', function() {




})

I was thinking of modifying the <li> element in this line of code :

 contents += '<tr><td title="' + data[i].toolTip[j] + 
    '" width="33%" style="padding-left:40px;"><ul style="list-style-type:  disc"><li>' + data[i].myDataDesc[j] + '  </li>';

to something like this :

 contents += '<tr><td title="' + data[i].toolTip[j] + 
    '" width="33%" style="padding-left:40px;"><ul style="list-style-type:  disc"><li dataDesc="'data[i].myDataDesc[j]'">' + data[i].myDataDesc[j] + '  </li>';

and then access it inside the above function like this :

var listItem = ($(this).attr('dataDesc'));

Is it a correct way to do this?

Here’s unmodified JSFiddle

Thank you for the sample code, that’s helped to make it nice and easy for exploration to occur.

You can get the list item by reference from the TR parent. Here’s how it can be done:

var tr = $(evt.target).parents("tr");
var text= $("li", tr).text();
console.log(text);

Thank you verymuch @Paul_Wilkins

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.