Explanation of Jquery Get with Example.

In this tutorial, you will learn how to get or set the element’s content and attribute value as well as the from control value using jQuery.

jQuery Get

Some jQuery methods can be used to either assign or read some value on a selection.

Three simple, but useful, jQuery methods for DOM manipulation are:

  • text() – Sets or returns the text content of selected elements.
  • html() – Sets or returns the content of selected elements (including HTML markup).
  • val() – Sets or returns the value of form fields.

When these methods are called with no argument, it is referred to as a getter, because it gets (or reads) the value of the element. When these methods are called with a value as an argument, it’s referred to as a setter because it sets (or assigns) that value.

Get Contents with text() Method

<script>

$(document).ready(function(){

$(“.btn-one”).click(function(){

var str = $(“p”).text();

alert(str);

});

});

</script>

<body>

<p>This is Roshan</p>

<button type=”button” class=”btn-one” >click</button>

</body>

Get Contents with Html() Method

<script>

$(document).ready(function(){

$(“.btn-two”).click(function(){

var str = $(“#rk”).html());

alert(str);

});

});

</script>

<body>

<p id =”rk”>This is <b>Roshan Kumar Jha</b></p>

<button type=”button” class=”btn-two” >click me</button>

</body>

Get Contents with Val() Method

<script>

$(document).ready(function(){

$(“.btn-two”).click(function(){

var str = $(“#title”).val());

alert(str);

});

});

</script>

<body>

<input type=”text” value=”Roshan Jha” id=”title” >

<button type=”button” class=”btn-two” >click me</button>

</body>

Related Posts

Strategic Certified FinOps Engineer integrates governance with cloud operations

Introduction The shift to cloud computing has fundamentally altered how businesses manage infrastructure, but it has also introduced significant financial complexities that many engineering teams struggle to…

Read More

Certified FinOps Manager Knowledge for Cloud Financial Governance

Introduction The shift toward cloud-native infrastructure has brought undeniable speed, but it has also introduced significant financial complexity. The Certified FinOps Manager is a professional designation designed…

Read More

Smart Career Growth Through Certified FinOps Architect Learning Journey

Introduction The Certified FinOps Architect is a professional certification designed to help engineers, cloud professionals, and managers optimize cloud financial operations and cost efficiency. This guide is…

Read More

CDOM – Certified DataOps Manager Learning Path for Modern Data Professionals

Introduction The CDOM – Certified DataOps Manager is a professional designation designed to bridge the gap between data engineering and operational excellence. This guide is written for…

Read More

Professional development journey using CDOA – Certified DataOps Architect

Introduction The CDOA – Certified DataOps Architect is a professional designation designed to address the unique challenges of managing and scaling data delivery in cloud-native environments. This…

Read More

Achieve Data Reliability with CDOE – Certified DataOps Engineer Program

Introduction The CDOE – Certified DataOps Engineer is established as a critical benchmark for professionals aiming to master the intersection of data engineering and operational excellence. This…

Read More