Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to trigger a click on a <code>&lt;span&gt;</code> that follows an <code>&lt;input type="text" class="gridTxtRow maxRow"&gt;</code> with a value of <code>VAL</code>, you can do this:</p> <pre><code>$('input.gridTxtRow[value="VAL"] + span').trigger('click'); </code></pre> <p>The selector <code>A + B</code> selects any <code>B</code> element that is the <a href="https://developer.mozilla.org/en/CSS/Getting_Started/Selectors#Information%3a_Selectors_based_on_relationships" rel="nofollow">next sibling</a> of an <code>A</code> element.</p> <hr> <p><strong>Update:</strong> There are some things you need to fix before getting this to work:</p> <ol> <li><p>Element IDs are suppose to be unique, i.e. there is only one element with a particular ID in the whole page. When you generate the <code>input.gridBtns</code> for a new option, it has IDs (<code>btn3</code>, <code>btn4</code>, etc.) as the buttons for the first option. Browsers will let you do this, but JavaScript that uses those IDs will become unpredictable.</p></li> <li><p>The <code>input.gridBtns</code> for a new option are only generated when the user clicks <code>[Open Grid]</code>. If the user clicks on the green plus button before clicking <code>[Open Grid]</code>, then there are no buttons to call <code>.trigger()</code> on. I suggest when you add a new option, you add those buttons as well.</p></li> </ol> <p>After these fixes, if you change this line:</p> <pre><code>$(plusbutton_clicked).closest('tr').find('input.gridTxtRow').val(gridValues); </code></pre> <p>to this:</p> <pre><code>$(plusbutton_clicked).closest('tr') .find('input.gridTxtRow').val(gridValues).end() .find('input.gridBtns[value="' + gridValues + '"]').trigger('click'); </code></pre> <p>it should do what you're looking for.</p> <hr> <p><strong>Update #2:</strong> Sorry, I thought you were adding new buttons after <code>[Open Grid]</code> when in fact you're moving <code>&lt;table class="optionTypeTbl"&gt;</code> around.</p> <p>Instead of the previous <code>$(plusbutton_clicked)...</code> code, try this:</p> <pre><code>$(plusbutton_clicked).closest('tr') .find('input.gridTxtRow').val(gridValues) .parent().append($('.optionTypeTbl')); $('#btn' + gridValues).trigger('click'); </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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