Edit td selector in createdCell
Edit td selector in createdCell
Hi!
I try to add a onclick event attribute to all <a> tags with the class "ocond" in a td.
so instead of giving the onClick event to the td like this:
$(td).attr('onClick', "saveToDatabase3(this,'pricechange','"+ rowData.price +"','"+ rowData.checkboxes +"')");
I try to give it to all <a> tags with class "ocond" within the td. I tried it with:
$(td + " a.ocond").attr('onClick', "saveToDatabase3(this,'pricechange','"+ rowData.price +"','"+ rowData.checkboxes +"')");
but I had no success. Thank you in advance for any help!
best greetings
This question has an accepted answers - jump to answer
Answers
I even tried it with:
$(td).children("ocond").attr('onClick', "saveToDatabase3(this,'cond','Mint','"+ rowData.checkboxes +"')");
but no success
$('a.ocond', td)
or$(td).children('a.ocond')
are what you want to use.That said, I would very much recommend against using DOM0 events. Use
$('#myTable').on( 'click', 'a.ocond', function () { ... } );
instead (not in thecreatedCell
callback - at the top level).Allan
Thank you Allen.
I do it in the createdCell area to get the rowData values (e.g. rowData.price).
If I do it outside of this area and inside the ready document area with a new on click event like you suggested, how could I get the specific td values of the different rowData inside the function?
best greetings and thanks in advance for any help
Using the
row().data()
method:The advantage of that is you only have one event and don't need to worry (as much) about memory leaks.
Allan
So I would be able to get the values with
var value = rowData.checkboxes
?
Because I get: "Cannot read property 'checkboxes' of undefined"
thank you in advance
Sorry - it should be
closest('tr')
not td!http://live.datatables.net/ruxadiwa/1/edit
Allan
great! that works! thank you very much Allan!