Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery replace button dropdown list with a label on click
    primarykey
    data
    text
    <p>I have a table with a button dropdown list as a column in each row. When the users selects from the dropdown I want the dropdown to be replaced by a label that reflects the selection they have made. I have this working but it will only on the first dropdown list.</p> <p>The rows are each identical to this, except different row numbers:</p> <pre><code>&lt;tr&gt; &lt;td&gt;1.&lt;/td&gt; &lt;td&gt; &lt;!-- Single button --&gt; &lt;div class="btn-group" id="MACdropdown"&gt; &lt;button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown"&gt; Action &lt;span class="caret"&gt;&lt;/span&gt; &lt;/button&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;a id="move" href="#"&gt;Move Assets&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="swap" href="#"&gt;SWAP Assets&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="add" href="#"&gt;Add Assets&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="cancel" href="#"&gt;Cancel Assets&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="change" href="#"&gt;Change Assets&lt;/a&gt;&lt;/li&gt; &lt;li class="divider"&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Entire Site Move&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt;4534-23423&lt;/td&gt; &lt;td&gt;123-234&lt;/td&gt; &lt;td&gt;346&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>JS:</p> <pre><code>$(document).ready(function(){ $("#MACdropdown").on('click' , 'a#move' , function(){ $('#MACdropdown').replaceWith('&lt;a href="viewassets-move.html"&gt;&lt;span class="label label-danger"&gt;MOVE&lt;/span&gt;&lt;/a&gt;'); }) $("#MACdropdown").on('click' , 'a#swap' , function(){ $('#MACdropdown').replaceWith('&lt;a href="viewassets-move.html"&gt;&lt;span class="label label-danger"&gt;SWAP&lt;/span&gt;&lt;/a&gt;'); }) $("#MACdropdown").on('click' , 'a#add' , function(){ $('#MACdropdown').replaceWith('&lt;a href="viewassets-move.html"&gt;&lt;span class="label label-danger"&gt;ADD&lt;/span&gt;&lt;/a&gt;'); }) $("#MACdropdown").on('click' , 'a#cancel' , function(){ $('#MACdropdown').replaceWith('&lt;a href="viewassets-move.html"&gt;&lt;span class="label label-danger"&gt;CANCEL&lt;/span&gt;&lt;/a&gt;'); }) $("#MACdropdown").on('click' , 'a#change' , function(){ $('#MACdropdown').replaceWith('&lt;a href="viewassets-move.html"&gt;&lt;span class="label label-danger"&gt;CHANGE&lt;/span&gt;&lt;/a&gt;'); }) }); </code></pre> <p>I would rather not have to make separate sets of JS statements for each dropdown list on the page. Example: changing #MACdropdown to #MACdropdown1 etc. and making separate functions.</p> <p>Check out the Fiddle for more info: <a href="http://bootply.com/75941" rel="nofollow">http://bootply.com/75941</a></p>
    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.
    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