Hello everyone and thank you for taking the time to answer my question.
I have a form with 6 selections with the "skillLevel" class. I need to get (preferably in an array) the values โโof each select element using jQuery.
How can i do this?
You can use the map method:
map
var arr = $('select.skillLevel').map(function(){ return this.value }).get()
arr is an array of values.
arr
var array = []; $('.skillLevel option:selected').each(function() { array[ $(this).val()] = $(this).text(); });
Something like this will do it for you.
var val = new Array(); $("select.skillLevel").each(function(){ val.push(this.value); });
Use it like
$(".skillLevel option:selected").each(function () { alert($(this).text()); });
Check out this script
http://jsfiddle.net/zF6HY/1/
Provided by: JqueryApi
Hope this fiddle helps you: All selected options
I think you should use $(".skillLevel") to select all the elements you want to get, then .val() over them and use .val() to extract the value of each element and process it as you like.
$(".skillLevel")
.val()
Hope this helps!
Source: https://habr.com/ru/post/925563/More articles:How to use the "this" link of the element that calls the function? - javascriptHow can I use the F () object to do this using Django ORM? - djangoResizing frames slowly when resizing () - jqueryHosting a subset of the boost used in a github project - c ++git merge repetitive conflicts - gitstart-stop-daemon does not write the nginx.pid file, even if the file is present - nginxHow to configure Intellij to run javap command in a program? - javaASP.NET MVC How to Manage User Content Using an ASP.NET Membership Provider - authorizationSQL Server 100% CPU Usage - One database shows higher CPU utilization than others - sql-serverUnable to scroll in UIScrollView as soon as UILabel / other subview is added to Storyboard - uilabelAll Articles