javascript - Jquery: if var equals liquid value then -
i'm still new jq, bare me please.
what i'm trying is: if variable equals value pulled shopify settings appends 1 piece of code, , if not-another.
jquery work shopify liquid. i've tried appending these codes without if statement. works perfectly. looks made syntax error somewhere, can't figure out where. can 1 point me plz?
here code
$(document).ready(function(){ var $bgset = {{settings.k_h}}; if ($bgset == color) { $('head').append('<style>html,body {background-color:{{settings.shop_bg_color}};}</style>'); } else { $('head').append('<style>html,body {background-image:url({{ 'mainbg.jpg' | asset_url }});}</style>');} }); thank you!
i assume you're trying compare $bgset see if equals string 'color'. mean both 'color' , $bgset need quoted:
$(document).ready(function(){ var $bgset = '{{settings.k_h}}'; if ($bgset == 'color') { $('head').append('<style>html,body {background-color:{{settings.shop_bg_color}};}</style>'); } else { $('head').append("<style>html,body {background-image:url({{ 'mainbg.jpg' | asset_url }});}</style>");} }); javascript jquery
No comments:
Post a Comment