Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selectpicker : Get the data attribute of selected option

I'm having hard time in to getting the data attribute set to select option on bootstrap selectpicker .

I tried:

$('.selectpicker').on('changed.bs.select', function (e) {
    var selected = e.target.value;
    console.log("value :  ", selected ); // gives selected value
    console.log("data attribute:  ", $(e.target).data("price")); 
});

data attribute always returns undefined

what wrong I'm doing here ?

like image 489
monda Avatar asked Dec 11 '22 07:12

monda


1 Answers

This works.

$('.selectpicker').on("changed.bs.select", function() {
    var dataTypeAttribute = $('option:selected', this).attr("data-type");
});
like image 155
Pranay Majmundar Avatar answered Dec 23 '22 16:12

Pranay Majmundar