html - jquery show data taken by select after removing parenthesis -


i have html select , div want show message depending on select option. <select id='select1'> shows options "player1(mike)" , want "player1" show in <div id='logid1'></div>. wrote following code

<script> $(document).ready(function(){          $("#select1").on("change", function() {             $("#logid1").html($(this).find(":selected").text(function(_, text) {                 return text.replace(/\(.*?\)/g, "");             }));          }); }); </script> 

it shows want result "player1" shows selected. i'm newbie in jquery ideas welcome.

currently modifying text of selected option, when use .text(fn) method.

you need .text() , perform desired operation.

$("#select1").on("change", function() {             $("#logid1").html($(this).find(":selected").text().replace(/\(.*?\)/g, "")); }); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -