tags:

views:

307

answers:

2

Hi, I have created a Div Tag inside menu li and added a Class Div1 to it. Everything working good.. But Now i want to create div tags with div1 ,and on another click div2 and then div3 .... So s it possible to use variable and have a counting inside it..Please Suggest me..

     $(document).ready(function(){


      $(".menu a").click(function () {

       $("<div> Label </div>").appendTo(".menu li").addClass("div1");
                            $(".div1").show(function () {
          $(".div1").editInPlace({
       url: "./server",
       show_buttons: true
              });//editinplace

             });//show
                        });//click
        });
+1  A: 

Not sure why you want to change the class, but in case you do that's included... i don't see the ID getting set....

$(document).ready(function()
{
    var increment = 0;
    $(".menu a").click(function () 
    {
        increment++;
        $("<div> Label </div>").appendTo(".menu li").addClass("div" + increment);
        $(".div" + increment).show(function () 
        {
            $(".div" + increment).editInPlace({
                url: "./server",
                show_buttons: true
            });//editinplace

        });//show
    });//click
});

the scope chaining in javascript means that the 'increment' variable is always visible to the click function.

Luke Schafer
Hi,Its working Good..But if i used $("div"+increment).html(); to get the changed value..Its showing simply Label..But i needed the value what i have edited so that i can insert that value into my database.Suggest me please...
Aruna
Hi,Believe it or not, I've never used jquery. I guessed the above example based on your code and my knowledge of javascript.You need to look up jquery and how to use that, maybe create another question for that part of the issue or update this question. I think I solved the original question as stated, however I would like to add this:You should be identifying the divs by ID not class, take a look at the jquery documentation.
Luke Schafer
A: 

I think you don't need to specify div1,div2 etc. I've used edit in place with jquery. I just add same class (like editable) to all the elements that I need to edit in place and put in ready function like this:

$(document).ready(function(){
    $(".editable").editInPlace(...../*other stuff*/);
});
TheVillageIdiot
SInce i need to fetch values of separate div..Im creating like this.
Aruna
@Aruna you can use $(this) to get html from the div that raised the event, that is the div that is clicked!
TheVillageIdiot