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

Certified AIOps Manager: Strategic Framework for Intelligent IT Operations

Introduction The Certified AIOps Manager program is a specialized training designed to help professionals lead the next wave of IT operations. This guide is for engineers and…

Read More

Advanced AIOps Architect Certification Roadmap for DevOps Engineers

Introduction The Certified AIOps Architect is a comprehensive professional program designed for engineers and architects who want to master the intersection of Artificial Intelligence and IT Operations….

Read More

Advanced Certified AIOps Professional Guide for Mastering AI Driven Operations Skills

Introduction Artificial Intelligence for IT Operations is the future of managing complex systems and large scale digital environments. The Certified AIOps Professional program is designed for those…

Read More

Certified AIOps Engineer Training to Boost Automation Monitoring and Career Growth

The Certified AIOps Engineer is a specialized professional program designed to integrate artificial intelligence into modern IT operations. As systems scale and generate massive amounts of telemetry…

Read More

Advanced Guide to AIOps Foundation Certification for Scalable IT Infrastructure

In an era where infrastructure and applications generate massive amounts of telemetry data, manual intervention is no longer a sustainable strategy for maintaining system uptime. The AIOps…

Read More

Advanced Certified Site Reliability Manager Learning Path for DevOps Teams

Introduction The Certified Site Reliability Manager program is an essential credential for those aiming to lead high-performance engineering teams in the modern era of cloud computing. As organizations transition…

Read More