EX - jQuery
Chris
Când se încarcă pagina.
$(document).ready(function(){
// cod
});
Manipulare cu un element "Clic"
$("element").click(function(){
$(this).func();
});
Exemple:
$(this).hide() - ascunde elementul curent.
$("p").hide() - ascunde toate <p> elemente.
$(".test").hide() - ascunde toate elementele cu class="test".
$("#test").hide() - ascunde elementul cu id="test".
Evenimente:
$("p").dblclick(function(){
$(this).hide();
});
Obțineți conținut - text(), html() , și val()
$("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});
$("#btn1").click(function(){
alert("Value: " + $("#test").val());
});
$("button").click(function(){
alert($("#w3s").attr("href"));
});
Set de conținut - text(), html() , și val()
$("#btn1").click(function(){
$("#test1").text("Hello world!");
});
$("#btn2").click(function(){
$("#test2").html("<b>Hello world!</b>");
});
$("#btn3").click(function(){
$("#test3").val("Dolly Duck");
});
jQuery addClass() Metoda
$("button").click(function(){
$("#div1").addClass("important blue");
});
$("button").click(function(){
$("h1, h2, p").removeClass("blue");
});