php - How to get id of clicked div jquery -


i have been trying id of clicked div of same classes different ids. tried know.

here 1 code tried (in one, .click function() not work .. edit: meaning not seem run code when clicked @ all!):-

$(".u_search").click(function() {     var attr_u_search = $(this).attr('id');     var datastring = '&u_search=' + $(".u_search").attr('id');     alert(datastring);      $.ajax({     type: "post",     url: '/script/profile.php',     data: datastring,     cache: false,     success: function(data) {           $('#ui_profile').show();           $('#ui_profile').html(data);           location.hash = 'profile' + 'id=' + datastring;           $(".searchbox").val('');           $("#usr_suggest").hide();      }   }); }); 

php:-

echo "<tr id='" . $id . "' class='u_search' height='40px'><td width='40px'><img class='avatar' src='$avater' /></td><td>" . $fname_ . " " . $lname_ . "</td></tr>"; }} 


here combination of codes tried (error in one: suppose have 5 divs, , if clicked 2nd div or 3rd div, captures id of first div [div 1] , not clicked div. want able capture id of clicked div.):-

$(".u_search").click(function() {     var attr_u_search = $(".u_search").attr('id');     var datastring = '&u_search=' + $(".u_search").attr('id');     alert(datastring);      $.ajax({     type: "post",     url: '/script/profile.php',     data: datastring,     cache: false,     success: function(data) {           $('#ui_profile').show();           $('#ui_profile').html(data);           location.hash = 'profile' + 'id=' + datastring;           $(".searchbox").val('');           $("#usr_suggest").hide();      }   }); }); 

php:-

echo "<tr id='" . $id . "' class='u_search' height='40px' onclick='javascript:op_prof(1)'><td width='40px'><img class='avatar' src='$avater' /></td><td>" . $fname_ . " " . $lname_ . "</td></tr>"; }} 

edit: when use first code (the 1 .click function()) code not seem run @ all! .. using jquery library version 1.9.1

inside function change

$('.u_search').attr('id') 

to

$(this).attr('id') 

the quotes important, not inside quotes ;)


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -