logiacer logiacer - 9 months ago 42
Javascript Question

Get name from option HTML with Javascript

<option value="1" name="13.890000">Monster</option>

I would like to get name via javascript to do calculations (On change) (NOTE: NOT VALUE)


Using, $(this).children(':selected').attr('name'); Your code should be something like: Here is the snippet

$("#select").on('change', function() {
  x =  $(this).children(':selected').attr('name');
  alert('the name is: '+x);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="select">
<option id ="#option1" value="1" name="13.890000">Monster</option>
<option id ="#option2" value="2" name="13.890000">Monster</option>