p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   How to access CSS using JavaScript? (http://p2p.wrox.com/showthread.php?t=66263)

Gary Frank February 28th, 2008 11:05 AM

How to access CSS using JavaScript?
I would like to use a JavaScript to get the values of CSS properties and to set them. But I am not sure how CSS is exposed in the DOM. I don't think that you can access CSS from server-side code-behind because CSS resides on the client. That's OK because I want to access it on the client with JavaScript.

How are CSS declarations exposed in the DOM? How can JavaScript access it?

joefawcett February 28th, 2008 12:11 PM

It depends somewhat on what you need to do. You can tinker with individual elements by accessing the style property, the className (CSS class) and the cssText. You can also access the linked and inline stylesheets, see this URL: http://www.javascriptkit.com/dhtmltu...ernalcss.shtml

IE and Gecko/Mozilla used to have slightly different names for some of the properties, no surprise there... I haven't done much development in this area recently so maybe things have improved.


Joe (Microsoft MVP - XML)

Gary Frank February 28th, 2008 01:32 PM

Thanks Joe. I have an ASP.NET page that pops up a FormView control that I enclosed in a DragPanelExtender so that the user can drag it to a convenient place on the page. The problem is that the DragPanel jumps back to the original position specified in the CSS every time a user clicks the FormView control or clicks a select button on the GridView that is its data source.

My idea is to adjust the CSS left and top properties for the panel when the ondrop event fires a JavaScript. The JavaScript would set the top and left properties to the current location of the panel. (I'm hoping I can GET the current location!)

I'm surprised at how much work it is to make a simple thing like that happen. But I'm using VS 2005. Maybe it got easier in VS 2008. Maybe there is another easier way to popup a draggable non-modal panel, tied to a row in the GridView, that provides a way for a user to add some data. This should be something that everyone does. I just am not aware of the best practice for this. Do you know of a way?

I'll take a look at the web site you recommended. Thanks!

All times are GMT -4. The time now is 04:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.