By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,953 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,953 IT Pros & Developers. It's quick & easy.

append div does't work

P: 2
I have a big problem. I'm trying to append a new div but it doesn't work.

My function is:

Expand|Select|Wrap|Line Numbers
  1. jQuery(function($){
  2.     var $meter = $('#analog_meter'), count = 1;
  3.     $('#addanalog').click(function(e){
  4.         e.preventDefault();
  5.         if(count > 2){
  6.             alert("That's enough already!");
  7.             return;
  8.         }
  9.         count ++;
  10.  
  11.         ($meter.parent()).append($meter.clone());
  12.     });
  13. });
Other function:

Expand|Select|Wrap|Line Numbers
  1. function add_new_analog()
  2. {
  3.     plotmychart(xmlhttp.responseText);
  4. }
And my sample of code to plot my analog meter is:

Expand|Select|Wrap|Line Numbers
  1. <div id="add" style="visibility:hidden;" style="display:inline-block;"><a id="addanalog" href="#" Onclick="add_new_analog();">ADD NEW ANALOG</a></div>
  2.  
  3. <div id="plot_analog">
  4.     <div id="analog_meter" name="analog_meter">
  5.         <!-- less information --> 
  6.         <div id="content-two" style="visibility:hidden;">
  7.                 <div id="chart1"  class="jqplot-target"></div>
  8.                 <a id="div-one" href="#" Onclick="mostra1();"><? echo LABEL_MORE_INFORMATION ?></a>&nbsp;&nbsp;  &nbsp;&nbsp;
  9.                 <a id="div-two" href="#" Onclick="mostra2();"><? echo LABEL_LESS_INFORMATION ?></a>
  10.         </div>
  11.         <!-- more information -->
  12.         <div id="content-one" style="visibility:hidden;">
  13.             <div id="chart2"  class="jqplot-target"></div>
  14.             <a id="div-one" href="#" Onclick="mostra1();"><? echo LABEL_MORE_INFORMATION ?></a>&nbsp;&nbsp;  &nbsp;&nbsp;
  15.             <a id="div-two" href="#" Onclick="mostra2();"><? echo LABEL_LESS_INFORMATION ?></a>
  16.         </div>
  17. </div>
  18.  
  19. </div>
What's happening is that every time I click ADD NEW ANALOG, plots two analog meters. like this:

what I want is that when click add, plot only one analog meter.

And, How can i change the id of the divs as long as i am appending new divs?

any idea how to help me?
Sep 24 '13 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
How can i change the id of the divs as long as i am appending new divs?
you either donít clone such elements or you donít use IDs.

PS. divs have no name attribute.
Sep 24 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.