ProfºEduardo Pezutti
http://maverick.td.utfpr.edu.br/slides/sw2 linkPega o texto (conteúdo) de uma marcação
$("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
Teste
Pega o texto (conteúdo) e as marcações html de uma marcação atingida
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});
Teste
Retorna o valor de um input, ou textarea
$("#btn1").click(function(){
alert("Value: " + $("#test").val());
});
Teste
Retorna o valor de um atributo
$("button").click(function(){
alert($("#w3s").attr("href"));
});
Teste
$("#btn1").click(function(){
$("#test1").text("Hello world!");
});
$("#btn2").click(function(){
$("#test2").html("<b>Hello world!</b>");
});
$("#btn3").click(function(){
$("#test3").val("Dolly Duck");
});
Teste
$("#btn1").click(function(){
$("#test1").text(function(i,origText){
return "Old text: " + origText + " New text: Hello world!
(index: " + i + ")";
});
});
Teste
$("button").click(function(){
$("#w3s").attr("href","http://www.w3schools.com/jquery");
});
Um ou
Múltiplos
$("button").click(function(){
$("#w3s").attr("href", function(i,origValue){
return origValue + "/jquery";
});
});
Teste
Coloca uma marcação no fim da seleção
$("p").append("Some appended text.");
Teste
Coloca uma marcação no início da seleção
$("p").prepend("Some appended text.");
Teste
Coloca o conteúdo DEPOIS ou ANTES da marcação selecionada
$("img").after("Some text after");
$("img").before("Some text before");
Teste
Remove a seleção e seus filhos
$("#div1").remove();
Teste e
Teste (com filtro)
Remove apenas os filhos
$("#div1").empty();
Teste
Adiciona uma class na seleção
$("button").click(function(){
$("h1,h2,p").addClass("blue");
$("div").addClass("important");
});
Teste 1 e
Teste 2
Remove uma class da seleção
$("button").click(function(){
$("h1,h2,p").removeClass("blue");
});
Teste
Adiciona / Remove uma class da seleção
$("button").click(function(){
$("h1,h2,p").toggleClass("blue");
});
Teste
Coloca CSS na seleção
$("p").css("background-color","yellow");
$("p").css({"background-color":"yellow","font-size":"200%"});
Teste 1 e
Teste 2
ProfºEduardo Pezutti
epsantos@utfpr.edu.br link