Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery selecting dynamic class id inside dynamically created div
    primarykey
    data
    text
    <p>I have some JS that dynamically creates a new div (inputs inside of a form). It works great. I separately have some jquery that checks a dropdown input, and shows a separate div if a specific selection is clicked. It works great. </p> <p>If I try to use the jquery to show a separate div inside one of the dynamically created ones, it does not work. The first instance of it does work, but none of the dynamically created ones. After searching around, it looks like I need a delegation, but I can't seem to figure it out for my specific situation. </p> <p>The JSFiddle: <a href="http://jsfiddle.net/Xyzeg/" rel="nofollow">http://jsfiddle.net/Xyzeg/</a> (change the "CPI" dropdown in the first field, for the event to go off). The fiddle includes the other JS for dynamically creating the divs.</p> <p>Any pointers would be appreciated.</p> <pre><code>&lt;div style="float:left"&gt; &lt;div id='dynamicInput'&gt;Pension 1: Amount: $&lt;input type='text' name='adjustmentInputs[]' value='0' size='13' maxlength='20'&gt;Start Year: &lt;input type='text' name='adjustmentInputs[]' value='2032' size='5' maxlength='6'&gt; &lt;input type='hidden' name='adjustmentInputs[]' value='2100'&gt; &lt;select name='adjustmentInputs[]'&gt; &lt;option value='InflationAdjusted'&gt;Inflation Adjusted&lt;/option&gt; &lt;option value='NotInflationAdjusted'&gt;Not Inflation Adjusted&lt;/option&gt; &lt;/select&gt;by &lt;select name='adjustmentInputs[]' class='pensionAdjustment1'&gt; &lt;option value='CPI'&gt;CPI&lt;/option&gt; &lt;option value='constantPercentage'&gt;Constant %&lt;/option&gt; &lt;/select&gt; &lt;div id='constantPercentageText1' style='display: none'&gt;@ &lt;input type='text' name='adjustmentInputs[]' value='3' size='5' maxlength='6'&gt;%&lt;/div&gt; &lt;/div&gt; &lt;input type="button" value="Add another Portfolio Adjustment" onClick="addInput('dynamicInput');"&gt; &lt;/div&gt; &lt;script&gt; $("[class*=pensionAdjustment]").change(function() { var n = $(this).attr('class').replace('pensionAdjustment', ''); var newId = "constantPercentageText" + n; var selectedItem = $(this).children('option:selected'); if ($(this).val() == 'constantPercentage') { $("#constantPercentageText" + n).css('display', 'inline'); $("#constantPercentageText" + n).show(); } else { $("#constantPercentageText" + n).css('display', 'none'); } }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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