2016-03-28 27 views
-1

Düğmeye basıldığında, bir sorgudaki metni başka bir metin parçasıyla nasıl değiştirebileceğimi merak ediyorum.Düğmeye basıldığında bir div içindeki metni değiştirmek için Jquery'yi kullanma

Div:

<div id="message">example message</div> 

Düğme:

Ben "test mesajının"

Bu online buldum ama işe yaramadı ile "örnek mesajı" değiştirmek istiyor

<input id="hideshow" type="button" value="here" onclick="replaceWith();"> 

:

$('#notes').on("click", "#hideshow", function(e){ 
    $("#message").replaceWith("test message"); 
}); 
+0

js olayları ve innerHTML, textContent vb yöntemleri öğrenin. – Jai

cevap

0
Try this.... 

    $(document).on("click", "#hideshow", function(e){ 
    $("#message").text("test message"); 
}); 
+0

Mükemmel çalıştı, teşekkürler! – Alex

1

Use 012 yerine replaceWith ait: Mesajı değiştirmek için metin yöntemi kullanmalısınız input

+0

İlgili olay hakkında emin misiniz? – Jai

+0

Üzgünüz, seni alamadım. –

0

Kullanım text(): Burada

$('#notes').on("click", "#hideshow", function(e){ 
    $("#message").text("test message"); 
}); 

fiddle olduğunu

0

için div ve val() için

$("#message").text("test message"); 
İlgili konular