rainy
rainy

Reputation: 1587

jQuery - How do I select an element by ID that has characters?

I working with the following form on a WordPress website:

<input id="abc_settings[update_date]" name= "abc_settings[update_date]" 
type="checkbox" value="1" <?php checked('1', $abc_options['update_date']); ?>/>

If I change the id to "update", I can select it using

value = $('#update').val();

However, I couldn't figure out how to get the value of abc_settings[update_date]. This one is not working:

value = $('abc_settings[update_date]').val();

I keep the name abc_settings so that I can use global $abc_settings and global $abc_options in WordPress.

Any help would be appreciated.

Upvotes: 0

Views: 58

Answers (1)

Blake Frederick
Blake Frederick

Reputation: 1670

Try to escape the [ and ] characters like this:

value = $('#abc_settings\\[update_date\\]').val();

I'm not entirely sure if that will work, but I'm basing it off of this:

http://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/

Upvotes: 1

Related Questions