Brampage
Brampage

Reputation: 6974

Find text between html tags and put it in a variable

I want to get the text between html tags e.g.:

<div id="text">
This is the text I want to put into a variable for later use.
</div>

This is what I want to do with the variable:

var = ????thedivtext????;

$(function(){
$("#text").val(thedivtext);
)}

Thanks...

Upvotes: 0

Views: 1714

Answers (2)

Adil
Adil

Reputation: 148140

You need text() function of jquery, text method does not give html tags if you require then use html()

Live Demo

var v = $("#text").text();

Upvotes: 2

Sajjan Sarkar
Sajjan Sarkar

Reputation: 4198

var text = $("#text").text(); will give you the text.

Upvotes: 2

Related Questions