0

This my code :

<?php
    if (isset($_GET["add"]))
    {
?>

<script type="text/javascript" language="javascript">
    var i=0;

    function createDiv()
    {
        $('#newdiv').append('<div id="div"'+i+'" class="ex" style="text-align: left;">Life Really suck</div>');

       i++;

       $( ".ex" ).draggable({containment:'parent',cursor:'pointer',opacity:0.6});
       $( ".ex" ).droppable();

    }

    createDiv(); // will execute when it loads this line
</script>

<?php
    }   
?>

<div id = "newdiv">    </div>

How can I make the function execute in the DIV outside of the condition statement?

I need the function execute normally is the GET["add"] is set

Now I it does not execute in the DIV even though the function does run

5
  • Can you please edit your message to correct typo and make it more clear ? I don't understand the problem nor what you want to do Commented Jun 4, 2013 at 8:09
  • I just want to append to the DIV, it doesn't work Commented Jun 4, 2013 at 8:14
  • It's Normal,You want to Append a content on a div, but your div don't exist, Create your div in Javascript, or, before your function. Commented Jun 4, 2013 at 8:21
  • I want to create it outside of the condition statement, is it possible? Commented Jun 4, 2013 at 8:26
  • Yes, Just Place your '<div id="newdiv"></div>' before your Php code in your page. ( and read other answer, your Jquery function isn't correct ^^ ) Commented Jun 4, 2013 at 8:28

1 Answer 1

2

surround your createDiv() call by $(document).ready(function(){ and }), this will execute what's inside only after the page is fully loaded.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.