0

I have a task to generate option using ajax in visual composer element, but when I try to select the element and attach an event using jQuery.. I can't trigger the event. Below is the jQuery script that I used to select the visual composer element.

jQuery('.post_id').on('change', function(){ console.log('Changed'); });

OR

jQuery(document).on('change', '.post-id', function(){ console.log('Change'); })

This is the screenshot of the visual composer element that I want to select using jQuery.

enter image description here

Thanks.

1 Answers1

1

replace '.post_id' to '[name=post_id]'

diavolic
  • 722
  • 1
  • 4
  • 5
  • Hi sorry, I delete my previous comment. So, my problem solved using this way... thanks diavolic. I use this code to select the element jQuery(document).on('change', '[name=post_id]', function(){ console.log('Change'); }). Thanks diavolic, by the way could you explain to me, why the class selector does not work? – Saddam Habibie Apr 11 '17 at 23:20
  • because '.post_id' will select elements by class name, and you want to use 'name' of element, not class. If you want to use class selector, add 'post-id' class to the existing class list in element and use your jquery code without changes – diavolic Apr 12 '17 at 01:39