Add the parameter event to the function and then get the element with currentTarget attribute
parseSerialNo: function(e){
var serialNo =$(e.currentTarget).text(); //get current target of event
console.log(serialNo);
},
Question
I'm trying to capture a value from a table on a click event.
events: {
'click .serial': 'parseSerialNo'
},
parseSerialNo: function(){
var serialNo = $('.serial').text();
console.log(serialNo);
},
HTML
<div class="col-md-4 serial">0005550</div>
<div class="col-md-4 serial">0008650</div>
<div class="col-md-4 serial">0067860</div>
what is the best way to grab the unique content within the div? Currently .text() returns all content in serial div (as it should). Do I need a this somewhere?
Solution
Add the parameter event to the function and then get the element with currentTarget attribute
parseSerialNo: function(e){
var serialNo =$(e.currentTarget).text(); //get current target of event
console.log(serialNo);
},