Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to get attribute from selected option using jQuery

by
Category:javascript
javascript jquery
How to get attribute from selected option using jQuery

The jQuery :selected selector can be used in conjugation with the val() method to find the selected option value in a select box or dropdown list. This tutorial teach you how to get attribute from selected option using jQuery.

HTML Code

<select id="language" >
    <option data-val="laravel" value="0">Laravel</option>
    <option data-val="php" value="1">PHP</option>
    <option data-val="ajax" value="2">Ajax</option>
</select>

jQuery Code

var data_val = $('#language option:selected').attr('data-val');
// Selected option attribute
var val = $('#language').val();
// Selected option value

0 Comments


Html code work in comment box


Related Post