How to take train_id current block when clicked?

 $("#tab-item-body").click(function() { console.log($(this).attr('train_id')); }); 

enter image description here

  • and what is the question? you have written how to take. so here, as you have written. by this attr - Captain Flint
  • one
    In html you cannot repeat the same id with different tags. Your html-code is incorrect - correct id first, and only then deal with train_id - andreymal

2 answers 2

 $(".tab-item-body").click(function () { console.log($(this).attr('train_id')); }); 

you need to select by class and not by id

     $("#tab-item-body").click(function(ev) { console.log($(ev.target).attr('train_id')); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div train_id="kek" id="tab-item-body"> Click me </div> 

    PS id elements must be unique.