Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing ) after argument list in jQuery

Tags:

jquery

I'm a complete jQuery noob. I'm grabbing button_types and and div variables but this is giving me the error:

<script>
    $(function(){
      $('div [button_type="'type'"]').addClass('active');
      $('div [image-var="'image'"]').addClass('active');
    });
    </script>

I've tried putting the ) in a multitude of locations but I'm guessing there's a bigger issue with my syntax that's causing this.

Probably an easy solution for someone that knows jQuery.

like image 995
Jake Avatar asked May 02 '26 23:05

Jake


2 Answers

You're missing the + signs with your variables:

$('div [button_type="' + type + '"]').addClass('active');
$('div [image-var="' + image + '"]').addClass('active');
like image 165
disinfor Avatar answered May 05 '26 13:05

disinfor


You're missing + when concatenating. Should be

$(function(){
      $('div [button_type="' + type + '"]').addClass('active');
      $('div [image-var="' + image +'"]').addClass('active');
    });
like image 30
code_alchemist Avatar answered May 05 '26 13:05

code_alchemist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!