domino
domino

Reputation: 7345

don't know how to use variables in jquery

$("#write").click(function(){
    $("#msg").$('#quote').html();

});

I am learning jquery (new to js as well). This function writes to a textbox id=msg. However I am having problems pulling the content.

How do I pull the content of a div and use in my function (#quote)? Right now it just writes #quote, not the content of the div called quote.

Also tried:

var quote = $("#quote").html();
    $("#msg").$(quote.val).html();

Out of ideas.

Upvotes: -1

Views: 108

Answers (3)

vishakvkt
vishakvkt

Reputation: 864

well I think you should do

 $("#msg").val($("#myDiv").html());

This will set the value of the div as the value of the textbox.

Upvotes: 0

N Rohler
N Rohler

Reputation: 4615

You have a syntax error. Try this:

$("#write").click(function(){
   var quote = $('#quote').html();
   $("#msg").html(quote);
});

Upvotes: 1

dvir
dvir

Reputation: 5115

just like you wrote, but the second line should be $("#msg").html(quote);.

The content of #quote is already in quote, and in order to replace the content of #msg with it, you pass it as a string to .html().

More about .html(): http://api.jquery.com/html/

Upvotes: 2

Related Questions