Support

Account

Home Forums Front-end Issues using file field urls in js/jquery Reply To: using file field urls in js/jquery

  • I don’t understand why you’re using $() around the url values returned by ACF

    
    <?php if( get_row_layout() == 'video' ):?>
      <?php if( get_sub_field('video_file') ): ?>
        <video id="<?php the_sub_field('video_id'); ?>"></video>
        <script>
          $(document).ready(function(){
            var videoFile = $('#<?php the_sub_field('video_id'); ?>');
            var videoM = '<?php the_sub_field('video_file_m'); ?>';
            var videoD = '<?php the_sub_field('video_file'); ?>';
            var WindowWidth = $(window).width();
            if (WindowWidth < 640) {
              //It is a small screen
              videoFile.append("<source src='"+videoM+"' type='video/mp4' >");
            } else {
              //It is a big screen or desktop
              videoFile.append("<source src='"+videoD+"' type='video/mp4' >");
            }
          });
        </script>
      <?php endif; ?>
    <?php endif; ?>