Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2008, 09:09 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default Switching back to class instead of style

Hi everyone,

My issue is pretty simple but tricky I guess. I dynamically set some style attributes to an element which were to read such attributes from a css class. Then When I clear these attributes by setting them to empty string I expect my element to reapply class attributes but it fails with some style attributes. My sample code is as follows, all attributes work fine and are restored correctly except for the "border" attribute. The border just disappears. what should I do generally in such situations?

.testClass{
    background-color:blue;
    width:200px;
    height:300px;
    position:absolute;
    top:10px;
    left:100px;
    border:solid red 1px;
}
.
.
.
<div class='testClass'>
    <button onclick='change(this.parentNode);'>
             Change Style
        </button>
    <button onclick='restore(this.parentNode);'>
             Restore Style
        </button>
</div>
.
.
.
<script language="javascript">
    function change(obj){
        obj.style.width="400px";
        obj.style.height="400px";
        obj.style.border="solid black 2px";
        obj.style.backgroundColor="white";
    }
    function restore(obj){
        obj.style.width="";
        obj.style.height="";
        obj.style.border="";
        obj.style.backgroundColor="";
    }
</script>



Best Regards,
Nerssi

 
Old September 23rd, 2008, 02:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I would have thought that you needed to reset the className attribute in the reset, maybe set to blank first, rather than simply assign empty values to the individual style attributes.

--

Joe (Microsoft MVP - XML)
 
Old September 23rd, 2008, 09:22 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do I set border style to blank instead of assigning empty value?

 
Old September 24th, 2008, 09:10 AM
Authorized User
 
Join Date: Jul 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You should be able to do obj.style.borderStyle = 'none';

Shawn Steward
Web Developer
www.shawnsteward.com
 
Old September 26th, 2008, 03:12 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The sample code is right up there. You can test and see that by setting the border to 'none' the border style would not be restored to its relevant class attributes (solid red 1px), while other attributes would...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Smalltalk-style class browser for VS? Raconteur Visual Studio 2005 3 May 3rd, 2007 11:10 AM
Custom style class oldSkool BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 0 January 9th, 2007 03:39 AM
difference between style.visibility and style.disp Mimi Javascript How-To 6 September 17th, 2003 11:50 PM
Recordset Style Class owain Pro VB 6 4 August 22nd, 2003 01:01 PM
Setting the Style Sheet class jacob ASP.NET 1.0 and 1.1 Basics 4 August 20th, 2003 01:53 AM





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