jquery value:
text(),html(),val().
.attr("href")
$("#test1").text("Hello world!");
$("#test2").html("<b>Hello world!</b>");
$("#test3").val("Dolly Duck");
$("#btn3").click(function(){
$("#test3").val("Dolly Duck");
});
====================
$("#btn1").click(function(){
$("#test1").text(function(i,origText){
return "Old text: " + origText + " New text: Hello world! (index: " + i +
")";
});
});
$("#btn2").click(function(){
$("#test2").html(function(i,origText){
return "Old html: " + origText + " New html: Hello <b>world!</b> (index:
" + i + ")";
});
});
======================
$("#w3s").attr("href","http://www.w3school.com.cn/jquery");
//Multiple properties
$("button").click(function(){
$("#w3s").attr({
"href" : "http://www.w3school.com.cn/jquery",
"title" : "W3School jQuery Tutorial"
});
});
$("button").click(function(){
$("#w3s").attr("href", function(i,origValue){
return origValue + "/jquery";
});
});
=========================
append() - insert content at the end of the selected element
prepend() - insert content at the beginning of the selected element
after() - insert content after the selected element
before() - insert content before the selected element
==========================
$("p").append("Some appended text.");
var txt1="<p>Text.</p>"; // create new element in HTML
var txt2=$("<p></p>").text("Text."); // create new element with jQuery
var txt3=document.createElement("p"); // create a new element from the DOM
txt3.innerHTML="Text.";
$("p").append(txt1,txt2,txt3);
==========================
$("img").after(txt1,txt2,txt3);
==========================
$("#div1").remove();
$("#div1").empty();
The following example removes all <p> elements with class="italic":
$("p").remove(".italic");
===========================
$("button").click(function(){
$("h1,h2,p").addClass("blue");
$("div").addClass("important");
});
You can also specify multiple classes in the addClass() method:
$("button").click(function(){
$("#div1").addClass("important blue");
});
$("h1,h2,p").removeClass("blue");
This method performs the switching operation of adding/deleting classes to the selected element:
$("button").click(function(){
$("h1,h2,p").toggleClass("blue");
});
======================
$("p").css("background-color");
//set up
$("p").css("background-color","yellow");
///
$("p").css({"background-color":"yellow","font-size":"200%"});
$("span").parentsUntil("div");
$("span").parents("ul");
$("span").parents();
$("span").parent();
========================
$("div").children("p.game"); p元素,game 类
$("div").find("span");
$("div").find("*");
$("h2").next();
$("h2").nextAll(); Sibling
===================
The following example selects the first <p> element inside the first <div> element:
$("div p").first();
$("div p").last();
$("p").eq(1); //Second element
Return all <p> elements with class name "intro":
$("p").filter(".intro");
$("p").not(".intro");
============================
$("#div1").load("demo_test.txt");
$("#div1").load("demo_test.txt #p1");