Reputation: 21893
I've got the following code
var addressPopupMenu = window.createPopup();
function showAddressPopup() {
var popup = document.getElementById('addressFullSpan');
popupMenuBody = popupMenu.document.body;
popupMenuBody.style.backgroundColor = "#336699";
popupMenuBody.style.border = "solid 2px; white";
popupMenuBody.style.fontSize="130%";
popupMenuBody.style.color="white";
popupMenuBody.style.padding="10px";
popupMenuBody.style.paddingLeft="30px";
As you can see I'm repeating popupMenuBody.style
. How can I give popupMenuBody.style
a css class so I dont have to repeat this for every popup
edit: it's not working
I've added popupMenuBody.className = "popups";
.popups
{
background-color: #29527A;
border: solid 2px; white;
fontSize:120%;
pcolor:white;
padding:10px;
paddingLeft:30px;
textTransform:capitalize;
}
also yes, i am including the .css in my page its working else where on the page
Upvotes: 2
Views: 1821
Reputation: 149524
To avoid overwriting existing classnames on popupMenuBody
, do this:
popupMenuBody.className += ' class_name';
Upvotes: 0
Reputation: 16419
To assign a CSS class to an element created in JavaScript, you can just use the following line of code:
popupMenuBody.className = "popups";
You've said that this doesn't work, but this is actually because your CSS is broken. I'm assuming that you've copy/pasted some JavaScript into your CSS file and changed it a bit, and as a result, your property names are all wrong. What you actually need for your CSS is this:
.popups
{
background-color: #29527A;
border: solid 2px white;
font-size:120%;
color:white;
padding:10px;
padding-left:30px;
text-transform:capitalize;
}
Notice that I have:
Your CSS should now get applied correctly.
Upvotes: 0
Reputation: 46008
popupMenuBody.className = "my class";
.popups
{
background-color: #29527A;
border: solid 2px white;
font-size: 120%;
color: white;
padding: 10px;
padding-left: 30px;
text-transform: capitalize;
}
Upvotes: 1
Reputation: 4738
Have you tried :
var addressPopupMenu = window.createPopup();
function showAddressPopup() {
var popup = document.getElementById('addressFullSpan');
popupMenuBody = popupMenu.document.body;
popupMenuBody.className = "className";
...
}
Upvotes: 0
Reputation: 10599
jQuery has the method addClass()
for applying a CSS class to an element
http://api.jquery.com/addClass/
Upvotes: 0
Reputation: 2426
I would do it using Jquery and addClass():
$('#addressFullSpan').addClass('name')
Upvotes: 0