jquery - Find list-item on data attribute after ajax -


through

$(this).attr('data');

we a-to-e data values list-item. like:

<li id="action" data="1-$b-$c-$d-$e">you rock 1</li> <li id="action" data="2-$b-$c-$d-$e">you rock 2</li> <li id="action" data="3-$b-$c-$d-$e">you rock 3</li> 

tried this, doesn't work:

var trackdata = $("[data='" + ........

the question, after handling ajax (with result success), find specific li-data clicked - , change bloody background color of clicked list item.

hope has best lesson me on this!

is you're looking for?

$(document).ready(function(){     $("li[data]").click(function(){         //data handling , ajax request here         $(this).css("background-color", "blue");     }); }); 

working example: https://jsfiddle.net/jfdcezpw/1/

edit: make more browser-friendly should use data-name="" instead of data="".


Comments