473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamically creating CSS

1
Hi I've got a bit of a problem. For a group project, we are creating a web based game, which involves things moving around on screen etc. I have figured out how to use AJAX to dynamically update everything on the page as and when it changes in our database, but the problem is:

I need to be able to dynamically create CSS

This is because we are using the CSS to "place" each player at a set point on the screen e.g.

#ship_1{
position: absolute;
left: 200px;
top: 200px;
background-image: url('images/ship-blue.jpg');
background-repeat: no-repeat;
background-position: center center;
border: 1px solid black;

height: 35px;
width: 64px;

z-index: 5;
}

I need to add code like this everytime a new player logs in.

Thanks in advance for your help
May 30 '07 #1
1 1151
gits
5,390 Expert Mod 4TB
hi ...

you may set every style you want for example the following way:

Expand|Select|Wrap|Line Numbers
  1. // get a reference to the desired dom-node (think it as: your player)
  2. var node = document.getElementById('id_of_your_player_node');
  3.  
  4. // set style - i.e. color
  5. node.style.color = 'red';
  6.  
  7. // or set a style that uses a slightly different style-attribute-name that
  8. // has then to be referred with the array-notation : background-color
  9. node.style['background-color'] = 'blue';
  10.  
  11. // you may also use predefined 'style-classes'
  12. node.className = 'your_css_class';
  13.  
  14.  
hope this helps and ...

kind regards
May 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
6
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.