Codxplore.com

Latest news:

Sahih al-Bukhari (সহীহ বুখারী) is a free Hadith application for android. This application is advertisement free. Download now https://play.google.com/store/apps/details?id=com.akramhossin.bukharisharif

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 : 1954

Subscribe Us


Follow Us