Codxplore.com

Latest news:

Quran ul karim is a free Quran application for android. This application is advertisement free application for android smartphone. Download from https://play.google.com/store/apps/details?id=com.akramhossain.quranulkarim&hl=en

jQuery text(), html(), and val() Usages


jQuery text(), html(), and val() Usages

In this blog post i will try to explain jQuery text(), html(), and val()  methods, there defination and uses.

jQuery text():

From the matched element jQuery text() method get the text contents of the particular element or Sets or returns the text content of selected elements

The following example demonstrates how to set content with the jQuery text()

$("#btn1").click(function(){
    $("#test1").text("Hello world!");
});

another demonstration of text() method

var pText = $("h1").text();
$("div").html(pText);

jQuery html():

From the set of matched elements we can Get the HTML contents of the first elemen or Sets or returns the content of selected elements (including HTML markup)

The following example demonstrates how to set content with the jQuery html()

$("#btn2").click(function(){
    $("#test2").html("Hello world!");
});

another example of html() method

$("div").html("

Hello

");

jQuery val():

From the set of matched elements Get the current value of the first element or Sets or returns the value of form fields

The following example demonstrates how to set content with the jQuery val()

$("#btn3").click(function(){
    $("#test3").val("Dolly Duck");
});

$("button3").click(function() {
  var text = $(this).text();
  $("input").val(text);
});

Tags : javascript, jQuery,

Views : 1494

Subscribe Us


Follow Us