Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery cloning html problem, update DOM?
    text
    copied!<p>I need help of javascript / jquery experts to solve the next problem:</p> <p>---- 1. <a href="http://www.texotela.co.uk/code/jquery/select/" rel="nofollow noreferrer">this javascript</a> alerts the id of a selected option in a select html tag: </p> <pre><code>$(function(){ $("#id_productos_list").change( function(){ var op = $(this).selectedValues() alert(op); } ); }); </code></pre> <p>----2. <a href="https://stackoverflow.com/questions/501719/dynamically-adding-a-form-to-a-django-formset-with-ajax">this javascript</a> clone html code: </p> <pre><code>function cloneMore(selector, type) { var newElement = $(selector).clone(); var total = $('#id_' + type + '-TOTAL_FORMS').val(); newElement.find(':input').each(function() { var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-'); var id = 'id_' + name; $(this).attr({'name': name, 'id': id}).val('').removeAttr('checked'); }); newElement.find('label').each(function() { var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-'); $(this).attr('for', newFor); }); total++; $('#id_' + type + '-TOTAL_FORMS').val(total); $(selector).after(newElement); } </code></pre> <p>---- this is a part of the HTML code that JS is cloning, and it works with no problems</p> <pre><code> &lt;select id="id_productos_list" name="productos_list" &gt; &lt;option value="1"&gt;One&lt;/option&gt; &lt;option value="2"&gt;Two&lt;/option&gt; &lt;/select&gt; </code></pre> <p>BUT just the javascript #1 works with the initial html code (original for clone). the cloned others doesnt alert selected options. I've tested with diferents id's attrs for each cloned select tags, without results.</p> <p>What im missing? firebug display the cloned html DOM nice :S Do I have to update DOM after cloning to make $("#id productos list").change(...) works?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload