Reputation: 1
I'm newbie jquery..
I don't know how can I compacted code for loop.
I have been saw the many code.
$('#fadeandscale1').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
$('#fadeandscale2').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
$('#fadeandscale3').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
$('#fadeandscale4').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
$('#fadeandscale5').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
$('#fadeandscale6').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
$('#fadeandscale7').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
$('#fadeandscale8').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
Upvotes: 0
Views: 38
Reputation: 32354
You can use the css3 selector [attribute^=value]
that selects a element based on the beginning of a attribute, the id
for us
$('div[id^="fadeandscale"]').popup({ pagecontainer: '.container', transition: 'all 0.3s' })
Upvotes: 2
Reputation: 87203
You don't need loop
for this, you can provide multiple comma-separated selectors as follow:
$('#fadeandscale1, #fadeandscale2, #fadeandscale3, #fadeandscale4, #fadeandscale5, #fadeandscale6, #fadeandscale7, #fadeandscale8').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
I'll recommend you to use common class
to all the elements of interest and use it as selector.
$('.fadeElems').popup({
pagecontainer: '.container',
transition: 'all 0.3s'
});
Upvotes: 2