javascript - Set value to an aria-controls input -


i want set input aria-control value. can't using traditional jquery way.

my code one:

function showmessage() {    var message = jquery("#texttodisplay").val();    $("#example").text(message);  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="text" id="texttodisplay" />  <input type="button" value="add message" onclick="showmessage()" />  <input aria-controls="example" type="text">

how can set value?

change selector this.your selector target id not aria-controls use attr selector.also input not have text() property change val()

function showmessage() {   var message = jquery("#texttodisplay").val();   $("input[aria-controls=example]").val(message);    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="text" id="texttodisplay" />  <input type="button" value="add message" onclick="showmessage()" />  <input aria-controls="example" type="text">

for below terry comment use addeventlistener instead of inline click function.that click function in dom this

$('#click').click(function() {    var message = jquery("#texttodisplay").val();    $("input[aria-controls=example]").val(message);  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="text" id="texttodisplay" />  <input type="button" id="click" value="add message">  <input aria-controls="example" type="text">


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -