: selected in Zepto.js

I get errors when executing .find ("option: selected") in Zepto.js. Is ": selected" even supported in Zepto? If not, is there an equivalent way to do this work without returning to jQuery?

+4
source share
5 answers

Due to the fact that I look through the documents, I do not think so. However, you should be able to:

var sel = document.getElementById("mySelect"); console.log(sel.options[sel.selectedIndex].value); 
+5
source

Zepto modules are not supported by default: selected because it is not a CSS standard, but you can add a Zepto “selector” module for this function (see the Zepto Github page for creating a library with additional modules).

Alternatively, this is a workaround mentioned in Zepto issues: https://github.com/madrobby/zepto/issues/503

 // get OPTION elements for which `selected` property is true $('option').not(function(){ return !this.selected }) 
+4
source

Try $('select').val(); This seems to work for me.

0
source

$("#YOURselectID").val(); should work fine.

Also :selected will not work perfectly zeptoJS

You can also try this to get the text of the selected item.

 $("#YOURselectID option["+$("#YOURselectID").val()+"]").html(); 

should work fine.

format $(ID option[value]).html();

0
source
 $('option:checked') 

In my project, I used the above for.

demo

0
source

Source: https://habr.com/ru/post/1394477/


All Articles