javascript - jquery selector for id starts with specific text -


this question has answer here:

i have jquery code:

$( "#editdialog" ).dialog({   autoopen: false,   show: {     effect: "blind",     duration: 1000   },   hide: {     effect: "explode",     duration: 1000   } }); 

but have several divs id's this: editdialog-0, editdialog-1, ...., editdialog-n.

how can make jquery code of these divs, 1 above?

use jquery starts with attribute selector

$('[id^=editdialog]') 

alternative solution - 1 (highly recommended)

a cleaner solution add common class each of divs & use

$('.commonclass').

but can use first 1 if html markup not in hands & cannot change reason.

alternative solution - 2 (not recommended if n large number) (as per @mihai stancu's suggestion)

$('#editdialog-0, #editdialog-1, #editdialog-2,...,#editdialog-n')

note: if there 2 or 3 selectors , if list doesn't change, viable solution not extensible because have update selectors when there new id in town.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -