Good day.
How to programmatically click on an element whose id will be known during the operation of the application? For example, I need to click on the element $("#Vopros32").click(); .
And how to substitute a number in id instead of 32?
Thank.

  • 2
    and what's the problem? Fold the two lines inside the selector, where the first line, say "#Vopros", and the second - a certain number (32 or any other) - DreamChild
  • one
    I think it is more correct to use something like a class, say, js-questions , and search for it by index, i.e. $('.js-questions').eq(32).trigger('click'); , produce ID for many elements of bad practice;) - ferrari

2 answers 2

@DreamChild, @Oleg B, I think you need to combine your thoughts:

 $("#Vopros" + id).trigger('click'); 
     var id = 32; $("#Vopros" + id).trigger('click');