Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to simplify a if/else jquery snippet
    primarykey
    data
    text
    <p>I have a super long jquery snippet that I feel could be simplified with the right logic. I'm afraid to touch it since I finally got it to work.</p> <p>the "else $target = #none" is literally a "show nothing" statement. I wasn't sure how to express that in a better way.</p> <p>Thanks so much! -zeem</p> <p>PS. links are to medical marijuana sites, so NSFW links!</p> <pre><code> $(function () { var $target = $('#CO1'); if (mmjsRegion == 'CO') { $target = $('#CO1'); } else { $target = $('#none'); } $target.imBannerRotater({ return_type: 'json', data_map: { image_name: 'name', url_name: 'url' }, image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CO1.php', base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/', }); }); $(function () { var $target = $('#CO2'); if (mmjsRegion == 'CO') { $target = $('#CO2'); } else { $target = $('#none'); } $target.imBannerRotater({ return_type: 'json', data_map: { image_name: 'name', url_name: 'url' }, image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CO2.php', base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/', }); }); $(function () { var $target = $('#CO3'); if (mmjsRegion == 'CO') { $target = $('#CO3'); } else { $target = $('#none'); } $target.imBannerRotater({ return_type: 'json', data_map: { image_name: 'name', url_name: 'url' }, image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CO3.php', base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/', }); }); $(function () { var $target = $('#CA1'); if (mmjsRegion == 'CA') { $target = $('#CA1'); } else { $target = $('#none'); } $target.imBannerRotater({ return_type: 'json', data_map: { image_name: 'name', url_name: 'url' }, image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CA1.php', base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/', }); }); $(function () { var $target = $('#CA2'); if (mmjsRegion == 'CA') { $target = $('#CA2'); } else { $target = $('#none'); } $target.imBannerRotater({ return_type: 'json', data_map: { image_name: 'name', url_name: 'url' }, image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CA2.php', base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/', }); }); $(function () { var $target = $('#CA3'); if (mmjsRegion == 'CA') { $target = $('#CA3'); } else { $target = $('#none'); } $target.imBannerRotater({ return_type: 'json', data_map: { image_name: 'name', url_name: 'url' }, image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CA3.php', base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/', }); }); </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. 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