1

I have a jQuery event defined as follows :

$('#pagebody').on('click', '#serverCompTab', function () {
    toggleTabs('#serverComp', '#serverCompTab');
});

I would like to trigger this event manually on my code like $('#'serverCompTab].onclick();

Can anyone help me with this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sasu
  • 423
  • 1
  • 6
  • 21

2 Answers2

2

Use click() instead of onclick() :

$('#serverCompTab').click();
//Or
$('#serverCompTab').trigger('click');

NOTE : you should replace ] by ) and move the quote to the end :

$('#'serverCompTab]
____^_____________^
    |             |__ //Replace it by ')'
    |__ //Move it to the end

Hope this helps.

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
1

You were really close. $('#serverCompTab').click() should take care of it for you.

Gavin
  • 4,365
  • 1
  • 18
  • 27