SET
Set Value by text()

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $("button").click(function(){

        $("#username").text("shishirphpdeveloper");

 

    });

});

</script>

</head>

 

<body>

<p>

<div id="username"></div>

<button>Show Value</button>

</body>

</html>

Set Value by val()

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $("button").click(function(){

        $("#username").val("shishirphpdeveloper");

 

    });

});

</script>

</head>

 

<body>

<p>

<input id="username" name="username" value=""/>

<button>Show Value</button>

</body>

</html>

Set Value by html()

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $("button").click(function(){

        $("#username").html("<b>Shishirphpdeveloper</b>");

 

    });

});

</script>

</head>

 

<body>

<p>

<div id="username"></div>

<button>Show Value</button>

</body>

</html>

Set Attributes value

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $("button").click(function(){

        alert($("#username").attr("name"));

    });

});

</script>

</head>

<body>

 

<p>

<input id="username" name="username" value="Test value"/>

<button>Show Value</button>

</body>

</html>


Previous
Next