Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のようにdivにテキストを追加しています
span.insertBefore("#text");
ここで、span は追加されるテキストを表します。ボタンクリックなどの他のイベントでテキストを取得するにはどうすればよいですか?
セレクターを使用してjquery要素のtext()関数を使用する必要があります
txt = $("#text").text(); //id selector txt = $('.classOfElement').text() //class selector
次のような JavaScript を使用してテキストを取得することもできます。
var text = document.getElementById('#text').innerHtml();