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,438
  • 68
  • 55
  • 126
Sasu
  • 383
  • 1
  • 5
  • 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
  • 65,304
  • 15
  • 70
  • 95
1

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

Gavin
  • 3,871
  • 1
  • 17
  • 27