Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply Same CSS to multiple ID's using Jquery

I need an html structure that looks like this:

<div id="ABTestBanner_New">
</div>

<div id="ABTestBanner_Fav">
</div>

<div id="ABTestBanner_Budget">
</div>

I need to use it in an AB split test. So I need to write in javaScript, and I need all three divs to be unique id's but have the same CSS. I tried to do it this way but only the #ABTestBanner_Budget is getting the CSS applied:

var $divNew = $('<div></div>', {'id': 'ABTestBanner_New'});
$('div.samplesCell.samples1').after($divNew)

var $divFav = $('<div></div>', {'id': 'ABTestBanner_Fav'});
$($divNew).after($divFav);

var $divBudget = $('<div></div>', {'id': 'ABTestBanner_Budget'});
$($divFav).after($divBudget);

$('#ABTestBanner_New' && '#ABTestBanner_Fav' && '#ABTestBanner_Budget').css({
    float : 'left',
    height : '250px',
    width : '950px',
    backgroundColor:'#0080FF',
    margin:'20px 0px 20px 0px'
});

Any thoughts on what I am doing wrong?

like image 447
gooser Avatar asked Dec 10 '25 14:12

gooser


1 Answers

See jquery docs here: http://api.jquery.com/category/selectors/

$('#ABTestBanner_New, #ABTestBanner_Fav, #ABTestBanner_Budget').css({
    /*your style*/
});
like image 61
maximkou Avatar answered Dec 13 '25 04:12

maximkou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!