javascript - Jquery set value of option element to be the text of the element -
i need set value attribute of alternative element equal text of alternative element itself. code have currently. reason concatenating strings.
here's html markup.
<select id="residentialbuildingtype" name="residentialbuildingtype"> <option>sfd</option> <option>test</option> </select> here's jquery code:
<script> $(document).ready(function () { var select = $('#residentialbuildingtype > option'); $(select).each(function (index) { console.log(select.text()); }); }); </script>
try utilize .attr() receiver function accomplish that,
$('#residentialbuildingtype > option').attr("value",function(){ homecoming $(this).text(); }); demo javascript jquery html
No comments:
Post a Comment