...

Library - JQuery

Back to Course

Lesson Description


Lession - #567 JQuery Set


The attr(>
method sets or returns attributes and values of the selected components. when this method is used to return the attribute value, it returns the value of the first matched component.

Set content methods
text(>
-
Sets or returns the text content of selected components

html(>
-
Sets or returns the content of selected components (including html markup>


val(>
-
Sets or returns the value of form fields

Example


<html>  
<head> 
 <title> jQuery Example</title>  
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">  
 <script>  
   $(document>
.ready(function(>
{ $("#btn1">
.click(function(>
{ $("#test1">
.text("Hello world!">
; }>
; $("#btn2">
.click(function(>
{ $("#test2">
.html("Hello world!">
; }>
; $("#btn3">
.click(function(>
{ $("#test3">
.val("techedhub">
; }>
; }>
; </script> </head> <body> <p id="test1">This is a set text.</p> <p id="test2">This is set html.</p> <p>Set value: <input type="text" id="test3" value="learning"></p> <button id="btn1">Set Text</button> <button id="btn2">Set HTML</button> <button id="btn3">Set Value</button> </body> </html>
Try it here