Programming techniques

about every things that i''m learning and want learn to other people

Programming techniques

about every things that i''m learning and want learn to other people

jQuery - Get and Set Content and Attributes

Query - Get Content and Attributes  

 

Set Attributes - text() -html() - val()  

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

  • 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 

 $("#btn1").click(function(){("Text: " + $("#test").text());)}

$("#btn2").click(function(){"HTML: " + $("#test").html());

$("#btn1").click(function(){"Value: " + $("#test").val());

Get Attributes - attr() 

 

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

$("#w3s").attr("href"));

 

 

 Set Attributes  

  

 Set Attributes - text() -html() - val()

We will use the same three methods from the previous page to set content:

  • 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 

 $("#btn1").click(function(){

$("#test1").text("Hello world!");

$("#btn2").click(function(){"#test2").html("<b>Hello world!</b>");

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

 Set Attributes - attr()   

 

$("button").click(function(){
$(
"#w3s").attr("href","http://www.w3schools.com/jquery");)}  

 

 

 

نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد