www.webdeveloper.com
Results 1 to 3 of 3

Thread: Set element's text as a target's value

  1. #1
    Join Date
    Nov 2010
    Posts
    56

    Set element's text as a target's value

    Hey,
    What I want to do is pretty simple, but I am very new to jquery. I can set text to a div by doing
    Code:
    $("#target").text("This is text");
    But what if I want the "This is text" to be replaced by the value currently in a text input? I have tried
    Code:
    $("#target").text(#input.val());
    and variations but it doesn't work..

    I can get what I want by doing this (but it's not very nice)
    Code:
    $("#test_div").text(document.getElementById("search_first_name").value);
    What should I use instead?

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    862
    I believe what you want would be:
    Code:
    $("#target").text($("#input").val());
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Nov 2010
    Posts
    56
    Quote Originally Posted by Sup3rkirby View Post
    I believe what you want would be:
    Code:
    $("#target").text($("#input").val());
    Awesome, thank you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles