-3

I have a bunch of links on a page:

<a href='#' class='link' id='1'>1</a>
<a href='#' class='link' id='2'>2</a>
<a href='#' class='link' id='3'>3</a>
<a href='#' class='link' id='4'>4</a>
<a href='#' class='link' id='5'>5</a>

These links open a modal that provides users a bunch of data. A user can edit some data and submit a form in this modal. After they are done, I want to reload the data in this modal.

how can i trigger a click based on the class and the id. Basically in laymans turns I want to:

$('.link' //That has id 4//).trigger('click');
mplungjan
  • 169,008
  • 28
  • 173
  • 236
bart2puck
  • 2,432
  • 3
  • 27
  • 53

1 Answers1

0

It is not recommended to have numeric IDs but this should work $("#4").click()

$(".link").on("click",function() { console.log(this.id) }); // show it works

$("#4").click()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href='#' class='link' id='1'>1</a>
<a href='#' class='link' id='2'>2</a>
<a href='#' class='link' id='3'>3</a>
<a href='#' class='link' id='4'>4</a>
<a href='#' class='link' id='5'>5</a>
mplungjan
  • 169,008
  • 28
  • 173
  • 236