Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery selecting div to change background on radio button click
    primarykey
    data
    text
    <p>I have a set of dynamic radio buttons that all show/hide certain fields when selected, and I'm trying to have the same jQuery block that shows and hide fields also show the correct preview image. It's for a wordpress theme. The container (tested with CSS setting background to an image) is called #layoutpreview. Here is the jQuery I'm using to switch the background-image:</p> <pre><code>if (layoutchecked =="tc") { jQuery('#CWP_layout').nextAll('div').hide('') var layoutchecked = jQuery('.radio_wrapper').children('input:checked').attr('value') if (layoutchecked =="tc") { jQuery('#CWP_tcblk1txt').show(''); jQuery('#CWP_tcblk1txt').addClass('setShowing'); jQuery('#CWP_tcblk1bgcolor').show(''); jQuery('#CWP_tcblk1icon').show(''); jQuery('#CWP_tcblk2txt').show(''); jQuery('#CWP_tcblk2bgcolor').show(''); jQuery('#CWP_tcblk2icon').show(''); jQuery('#CWP_tcblk3txt').show(''); jQuery('#CWP_tcblk3bgcolor').show(''); jQuery('#CWP_tcblk3icon').show(''); jQuery('#layoutpreview').css("background-image", "url('images/previews/3-column-layout.jpg')"); alert ("we changed it"); } } </code></pre> <p>The HTML is being written as the WordPress theme takes in an array, and spits out radio buttons, here is the generated HTML code:</p> <pre><code>&lt;div id="CWP_layout" class="cwp_input cwp_radio"&gt; &lt;label for="CWP_layout"&gt;Select Layout&lt;/label&gt; &lt;div class="radio_wrapper"&gt; &lt;input type="radio" name="CWP_layout" value="tc" checked='checked' class="CWP_layout"/&gt;Three Columns&lt;br /&gt; &lt;input type="radio" name="CWP_layout" value="tr" class="CWP_layout"/&gt;Three Rows&lt;br /&gt; &lt;input type="radio" name="CWP_layout" value="is" class="CWP_layout"/&gt;Image Slider&lt;br /&gt; &lt;input type="radio" name="CWP_layout" value="iwc" class="CWP_layout"/&gt;Image with Content&lt;br /&gt; &lt;input type="radio" name="CWP_layout" value="osi" class="CWP_layout"/&gt;One Single Image&lt;br /&gt; &lt;input type="radio" name="CWP_layout" value="fsev" class="CWP_layout"/&gt;Full Size Embedded Video&lt;br /&gt; &lt;input type="radio" name="CWP_layout" value="vwti" class="CWP_layout"/&gt;Video with Three Images&lt;br /&gt; &lt;/div&gt; &lt;small&gt;Select the layout for the theme.&lt;/small&gt;&lt;div class="clearfix"&gt;&lt;/div&gt; &lt;div id="layoutpreviewwrap"&gt;Layout Of Selected Theme&lt;div id="layoutpreview"&gt;&lt;/div&gt;&lt;br /&gt; &lt;/div&gt; &lt;/div&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.
    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