In this post we will take a look on how to perform two common tasks using jQuery . We will see how following tasks can be performed,
- Reading and setting text of label
- Reading value of selected item from drop down
Reading and setting text of label
Let us say you have label on HTML as following,
<label id="locationbox"> </label>
You can read value as following ,
var valueoflabel = $('#locationbox').text();
You can set text in label as following,
$('#locationbox').text("MyText");
Reading value of selected item from drop down
Let us say you have drop down as following on html,
<select id="typeofreport"> <option value="Rape">Rape</option> <option value="EveTeasing">Eve Teasing</option> <option value="Molestation">Molestation</option> <option value="VerbalAbuse">Verbal Abuse</option> <option value="Harassmentatwork">Harassment at work</option> </select>
You can read text of selected value of drop down as following ,
var typeofincident = $("#typeofreport option:selected").text();
These are the two tasks I wanted to share with you. I hope you find this small blog post useful. Thanks for reading.
One thought on “Two common tasks using jQuery”