jquery - selecting unique id

blogo3x

i'm new to jquery

i generated html div with php and give each them a unique id

<div id=div1>text</div>
<div id=div2>text</div>
<div id=div3>text</div>
...

the problem is, how I select specific div with jquery? usually i use this code to select an element

$('#id')

but I have to make alot of selector because each id is unique. Recently I used something like this

<div ... onclick=getElem(id)></div>

function getElem(id){
     var elem=$('#div'+id);
} 

Is it good to use onclick?

Populus

Add a class to the group of divs

<div id="div1" class="someClass">text</div>
<div id="div2" class="someClass">text</div>
<div id="div3" class="someClass">text</div>
...

Then in javascript:

$('.someClass').click( function(event) {
    var ele = $(this);
    // ele is the element you clicked on
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Selecting ID of a element in Jquery

From Dev

Selecting ID of a element in Jquery

From Dev

jQuery if statement selecting an Id

From Dev

Selecting ID + any number in jquery

From Dev

Selecting ID + any number in jquery

From Dev

Selecting unique values from multiples array in Jquery

From Dev

Jquery selecting dynamic id and execute that particular id

From Dev

jQuery not selecting id containing "<" angular bracket?

From Dev

Selecting an element with Id having colons in Sizzle/jQuery

From Dev

Jquery selecting element by 'data-id'

From Dev

Selecting by class and applying styles by id with jQuery on click

From Dev

Jquery selecting element by 'data-id'

From Dev

jQuery not selecting id containing "<" angular bracket?

From Dev

Selecting the latest entry of multiple unique category ID's

From Dev

selecting unique combination of columns

From Dev

selecting unique combination of columns

From Dev

Selecting unique rows in R

From Dev

JQuery:Selecting second element in case element with same ID exists

From Dev

jquery error when selecting controls with id which contains empty spaces

From Dev

Selecting an element within an element with different ID names or class name in jQuery

From Dev

jQuery: selecting an element having a certain id and a certain class, both as variables

From Dev

Jquery Programatically Click button with no unique id or class

From Dev

how to add a unique ID into a class with javascript/jquery

From Dev

Selecting single row with no unique key

From Dev

Not selecting duplicate records with unique keys

From Dev

Selecting unique values from SQL

From Dev

SQL selecting the ID with the name

From Dev

SQL selecting the ID with the name

From Dev

Selecting MapPoint via ID

Related Related

  1. 1

    Selecting ID of a element in Jquery

  2. 2

    Selecting ID of a element in Jquery

  3. 3

    jQuery if statement selecting an Id

  4. 4

    Selecting ID + any number in jquery

  5. 5

    Selecting ID + any number in jquery

  6. 6

    Selecting unique values from multiples array in Jquery

  7. 7

    Jquery selecting dynamic id and execute that particular id

  8. 8

    jQuery not selecting id containing "<" angular bracket?

  9. 9

    Selecting an element with Id having colons in Sizzle/jQuery

  10. 10

    Jquery selecting element by 'data-id'

  11. 11

    Selecting by class and applying styles by id with jQuery on click

  12. 12

    Jquery selecting element by 'data-id'

  13. 13

    jQuery not selecting id containing "<" angular bracket?

  14. 14

    Selecting the latest entry of multiple unique category ID's

  15. 15

    selecting unique combination of columns

  16. 16

    selecting unique combination of columns

  17. 17

    Selecting unique rows in R

  18. 18

    JQuery:Selecting second element in case element with same ID exists

  19. 19

    jquery error when selecting controls with id which contains empty spaces

  20. 20

    Selecting an element within an element with different ID names or class name in jQuery

  21. 21

    jQuery: selecting an element having a certain id and a certain class, both as variables

  22. 22

    Jquery Programatically Click button with no unique id or class

  23. 23

    how to add a unique ID into a class with javascript/jquery

  24. 24

    Selecting single row with no unique key

  25. 25

    Not selecting duplicate records with unique keys

  26. 26

    Selecting unique values from SQL

  27. 27

    SQL selecting the ID with the name

  28. 28

    SQL selecting the ID with the name

  29. 29

    Selecting MapPoint via ID

HotTag

Archive