help to move jquery to javascript.
help to move jquery to javascript.
Please can someone help me as I am moving across to Datatables 3 from 2 and removing all JQuery.
I use the following but cannot "translate" it into javascript. If anyone can help me, I would be very greatful.
editor.dependent("colour", function () {
var label = editor
.field("colour")
.input()
.find("option:selected")
.text();
editor.val("code", label);
return {};
});
This question has an accepted answers - jump to answer
Answers
This is the one bit that will trip you up since
:selectedis a jQuery extension and you'll probably be getting an invalid selector error with that?If you just need the value from the
selectlist, use:However, the label and the value are not always the same in a
select(apologies if this is preaching to the choir!), so it could be that you want to actually get the text content for the selectedoption, in which case:will do the job, exactly matching what you have with the jQuery selector.
Allan
Thank you very much for your swift answer. All working perfectly, thank you.
NB: The equivalent of jQuery's
option:selectedisoption:checked. So:would become:
Or
querySelectorAllfor a multi-select list.Alternatively, you can use the
selectedOptionscollection.Doh - I should have remembered that. Many thanks!
Allan