Ask Your Question
3

How can I retrieve the text from a span using Jquery?

asked 2022-08-29 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-01-05 20:00:00 +0000

devzero gravatar image

You can retrieve the text from a span using jQuery by using the .text() method. Here's an example:

// HTML
<span id="my-span">Hello, world!</span>

// jQuery
var text = $('#my-span').text(); // retrieves the text inside the span element
console.log(text); // prints "Hello, world!" to the console

In the above example, we select the span element using its ID and then use the .text() method to retrieve the text inside it. We then store the text in a variable called text and print it to the console using console.log().

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-29 11:00:00 +0000

Seen: 15 times

Last updated: Jan 05 '23