Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4537364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:39:56+00:00 2026-05-21T14:39:56+00:00

I have uploaded my code to JSfiddle: http://jsfiddle.net/TSM_mac/pnQEe/ I want to be able to

  • 0

I have uploaded my code to JSfiddle:

http://jsfiddle.net/TSM_mac/pnQEe/

I want to be able to type into the text inputs on the page, and click the “Add Div Type” button, and it will append (create) the div element inside of the div you click on (that has the class = “editable”).

I have having difficulty making this code work. Can anyone find where I went awry?

Code

var $currentInput = null;

$("#add_div1, #add_div2, #add_div3").click(function() {
    $currentInput = null;
    if ($currentInput == null) {
        $currentInput = $(this).prev();
        $("label").html($currentInput.attr("id"));
    }
});


var editid;
$("div.editable").click(function(e) {
    e.stopPropagation();
    if ($currentInput == null) return;
    editid = $(this).attr("id");
    var adddiv = GetElements();
    $(this).append(adddiv);
    $("label").html("");
});

function GetElements() {
    if ($currentInput == null) return null;

    var value = $currentInput.val();

    if ($currentInput.attr("id") == "add_div1") return {
        "<div>"+value+"</div>"
    }
    if ($currentInput.attr("id") == "add_div2") return {
        "<div>"+value+"</div>"
    }
    if ($currentInput.attr("id") == "add_div3") return {
        "<div>"+value+"</div>"
    }
}

–

<input type="text" id="add-div1" value="Content of Div 1" />
<div id="add_div1">Add Div Type 1</div>
<input type="text" id="add-div1" value="Content of Div 2" />
<div id="add_div2">Add Div Type 2</div>
<input type="text" id="add-div1" value="Content of Div 3" />
<div id="add_div3">Add Div Type 3</div>



<div id="2" class="defaultclass editable">
    Add a Div Here
</div>
<div id="3" class="defaultclass editable">
     Add a Div Here
</div>
<div id="4" class="defaultclass editable">
    Add a Div Here
</div>

<label></label>

–

input { display: block; padding-top: 10px; }
#add_div1, #add_div2, #add_div3 { background: #c0c0c0; border: solid 1px #777; display: inline-block; }

.editable { border: solid 5px green; margin: 20px; background: blue; color: #fff; }

Regards,

Taylor

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:39:56+00:00Added an answer on May 21, 2026 at 2:39 pm

    this one works now

    http://jsfiddle.net/pnQEe/5/

    (I added some console.log but now is commented out)

    seems like your code is that you need to click the button and then click the div

    Issue #1: you have return { ... } It should be { return ... } or just return ...

    Issue #2: you have add-div1 but the code checked against add_div1 (underscore, not hyphen)

    Also, I try not to have two elements with the same or similar id name as well. (such as add-div1 for the text input, and add_div1 for the button — looks too similar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: http://jsfiddle.net/J6vzU/1/ I want to dynamically display thumbnail of uploaded file
I have uploaded the following simple HTML code to http://losthobbit.net/temp/anchor.html <!DOCTYPE HTML PUBLIC -//W3C//DTD
I have uploaded a page with the code below to my joomla root directory.
I have uploaded a text file to my database into a Image field. The
I have my asp .net website. I have uploaded that. But is shows code
I have uploaded my code to pastebin, this is the link: http://pastebin.com/wBu9PP2x When i
Once you have uploaded your source code to Heroku, is it possible to download
In asp.net, we have uploaded a .jpeg file and saved this as bitmap image
So, I have the code below which works fine when entered into Google's Rich
I have successfully converted the FullCalendar into asp.net / VB and it works perfectly.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.