Note that there are some explanatory texts on larger screens.

plurals
  1. POMatching Variables of Two Elements (binding cycle and ui-selectable)
    primarykey
    data
    text
    <p>I need help with condensing my script so that a #div_x is related to a separate element img_x.</p> <p>My project uses ui-selectable to grab points on a map and return an image set in a separate div via jquery cycle (as in here <a href="http://bit.ly/gH7Lm3" rel="nofollow">http://bit.ly/gH7Lm3</a>).</p> <p>I have bound the 'selectablestop' event to two functions - .hasClass and .append - in order to 1) detect if a point has been selected and 2) append the containing cycle div with a corresponding image (also, incidentally, contained within its own div). As is, it looks something like this:</p> <pre><code>$("#selectable").selectable().bind("selectablestop", function(event, ui) { if($('#point_a').hasClass('ui-selected')){ $('#cycle').append('&lt;div id="pic"&gt;&lt;img src="image_a.jpg" /&gt;&lt;/div&gt;');} if($('#point_b').hasClass('ui-selected')){ $('#cycle').append('&lt;div id="pic"&gt;&lt;img src="image_b.jpg" /&gt;&lt;/div&gt;');} if($('#point_c').hasClass('ui-selected')){ $('#cycle').append('&lt;div id="pic"&gt;&lt;img src="image_c.jpg" /&gt;&lt;/div&gt;');} </code></pre> <p>, etc.</p> <p>My question:</p> <p>Can I accomplish this with one argument, using a variable x instead of writing out each line matching point_a to img_a, point_b to img_b, etc. That is,</p> <pre><code>if($('#point_(variable)').hasClass('ui-selected')){ $('#cycle').append('&lt;div id="pic"&gt;&lt;img src="image_(matching variable).jpg" /&gt;&lt;/div&gt;');} </code></pre> <p>Thanks! I've spent some time looking for a good approach.</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.
    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