skip to Main Content

I would like to change the font-family:'Pinyon Script'; in my css to font-family:'Ariel'; through select input data-fields. I am printing a text on a product based on customer choices. I searched the question database and tried the different ‘ " "’ options around the font names but it did not help. Is my script correct?

<form>
<input data-field-id="5f0124e773aa8" />
<select data-field-id="5f012882c6562">
<option data-wapf-label="handwriting">handwriting</option>
<option data-wapf-label="typewriting">typewriting</option>
</select>
<div class="woocommerce-product-gallery--with-images"></div>
</form>
jQuery(document).ready(function($) {
    
    var fieldId = "5f0124e773aa8"; 
    var defaultText = "My name"; 
    
    if(!jQuery('input[data-field-id="'+fieldId+'"]').length)
        return;
        
    var $el = jQuery('<div class="sw_poster_text2">').html(defaultText);
    $el.appendTo(jQuery('.woocommerce-product-gallery--with-images'));
    
    jQuery(document).on('change keyup','input[data-field-id="'+fieldId+'"]',function(){
        var v = jQuery(this).val() || defaultText;
        jQuery('.sw_poster_text2').html(v);
        
    }).trigger('change');
    $("select[data-field-id='5f012882c6562']").change(function() {
        var font-family = $(this).find('option:selected').data('wapf-label');
        if(font-family == 'handwriting')
            font-family = 'Pinyon Script';
        if(font-family == 'typewriting')
            font-family = 'Arial';
        $(".sw_poster_text2").css("font-family", font-family);
    });  
});

2

Answers


  1. Try changing the "font-family" variable to "font_family". JavaScript does not accept "-" in variable names.

    Login or Signup to reply.
  2. The syntax for accessing css properties is covered in the jQuery documentation. You’ll need to pay attention to whether you’re accessing font-family via a javascript attribute (in which case, it’s fontFamily, or via a property (in which case, it’s "font-family").

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search