You are viewing limited content. For full access, please sign in.

Discussion

Discussion

Forms - Accessing fields by ID instead of Class using Jquery seems unreliable

posted on April 2, 2019

I am trying to use the ID instead of the class name for fields. I use the developer tools to lookup the ID of the fields but jquery does not appear to work. I swapped the . character for a # character and it works with some fields, but not with fields that have parentheses in the name.

This errors 

    $('#Field55(3)').val('1'); 

Classic javascript works

    var changed = document.getElementById('Field55(3)');
      changed.value = 1;

Is there a limitation to jquery with parentheses characters?

0 0
replied on April 2, 2019

This is because ( and ) are special characters in jQuery and need to be escaped out. To escape out you have to use a double backslash (\\) for it to work right.

https://api.jquery.com/category/selectors/

1 0
replied on April 2, 2019

Awesome, thanks Michael!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.