javascript - inspect element with jquery -


i want id(or class) of element when clicked on that. write codes.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>    <script>    $(document).ready(function() {      $('*').click(function() {        var idname = $(this).attr('class');        alert(idname);      });    });  </script>  <div class="test">    <div class="test1">      <div class="test2">        test      </div>    </div>  </div>

but give me class(id) of parent class.(and undefined) how can delete that?(give me class(or id) of 1 element)

add event.stoppropagation , use event.target:

  $(document).ready(function() {     $('*').click(function(e) {       e.stoppropagation();       var idname = $(e.target).attr('class');       alert(idname);     });   }); 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -