I need to change the style of an element changing its padding-left property (got it in firefox but IE is a different battle..). I can use document.getEle mentById().styl e.XX
to everything i need, except with padding-left, as it is separated by a ' - ' and it is not correct to use it as it was supposed to:
document.getEle mentById('el'). style.padding-left = '5px'
will throw 'invalid assignment left-hand side', as expected..
Any help please?
[SOLVED]
Apparently the property turns into paddingLeft (or paddingTop, paddingBottom, paddingRight) so it can be used as expected:
document.getEle mentById('el'). style.paddingLe ft = '5px'
document.getEle mentById('el'). style.paddingTo p = '5px'
document.getEle mentById('el'). style.paddingRi ght = '5px'
document.getEle mentById('el'). style.paddingBo ttom = '5px'
2 13906 hsriat 1,654
Recognized Expert Top Contributor
I need to change the style of an element changing its padding-left property (got it in firefox but IE is a different battle..). I can use document.getEle mentById().styl e.XX
to everything i need, except with padding-left, as it is separated by a ' - ' and it is not correct to use it as it was supposed to:
document.getEle mentById('el'). style.padding-left = '5px'
will throw 'invalid assignment left-hand side', as expected..
Any help please?
For that use paddingLeft.
In general, anything of style containing a hyphen ( - ) will work for JavaScript when hyphen is removed and first letter of the second word is made capital.
eg.
background-image -> backgroundImage
border-top -> borderTop
[EDIT]
Glad to know you solved it.
Converting between css syntax('border-top-width') and javascript property names ('borderTopWidt h') is a common webpage chore.
The values you are working with are always strings, so a String method to do the conversion may be appropriate: -
-
String.prototype.dash= function(boo){
-
var s= this;
-
if(/^[A-Z]+$/.test(s) || /\-/.test(s)) s = s.toLowerCase();
-
if(boo=== true ){
-
if(/[a-z][A-Z]/.test(s)){
-
s= s.replace(/[A-Z]/g, function(w){
-
return "-" + w.toLowerCase();
-
})
-
}
-
}
-
else if(/\-/.test(s)){
-
s= s.replace(/\-[a-z]/g, function(w){
-
return w.charAt(1).toUpperCase() + w.substring(2);
-
})
-
}
-
return s;
-
}
-
// pass the argument 'true' for css (hyphen-ated) , leave it out or pass 'false' to return camelCase.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Chris |
last post by:
Hi, I'm having a problem utilizing the DOM. I tried using my own
code, but it wasn't working, so I tried to use code straight from
another web site and it verified that the problem may not be mine. I
am using IE 6.0.28 (sp5) on a Windows 2000 Server.
I am very new to DOM so I'm not ruling out that I'm doing something
wrong. However, I am posting the code that I got from another site
because I did notice that the examples were using...
|
by: Jaap |
last post by:
Hi,
For a hobby site, I found this script and I'd like it to work the other way
around. The content has to show and the visitor has to click to hide it.
Could someone help me please? I'm a total Java-newbie...
TIA
Jaap
Here's the code:
|
by: lawrence |
last post by:
The following function correctly makes everything invisible but then
fails to turn the one chosen DIV back to visible. I imagine I'm
getting the syntax of the variable wrong? I've tried this with both
single quotes and no single quotes, but it doesn't work either way.
What am I doing wrong?
<SCRIPT type='text/javascript'>
function makeVisible(nameOfDiv) {
document.getElementById('weblogs').style.visibility='hidden';
|
by: lawrence |
last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in
IE???
<SCRIPT type='text/javascript'>
function makeVisible(nameOfDiv) {
document.getElementById(nameOfDiv).style.visibility='visible';
document.getElementById(nameOfDiv).style.height='auto';
if (nameOfDiv != 'weblogs')
|
by: Ghyslaine Crespe |
last post by:
Hello,
In my script, the line
document.getElementById(id).style.background-position = "-200px -500px";
fails !
So, how can I change the background-position value ?
| |
by: s_m_b |
last post by:
function saveState() {
document.write (" | <a href = 'myhomepage.asp?
view=mhp&action=save&pb=");
>> document.write (document.phone.style.display.value);
document.write ("'>save view</a>");
};
creates an error at this (>) line.
|
by: PaulB |
last post by:
Good Morning everybody,
I'm trying to adapt a tutorial script that will handle the behaviour of an
"Expanding/Contracting" site-navigation menu. The code that seems to
handle the expansion and contraction follows at the bottom of my
message here.
This following line is a big part of my hang-up:
document.getElementById('m1').style.display='none';
|
by: therig |
last post by:
I'm having issues, I've spent many hours searching and I'm a noob at javascript, any help will be greatly appreciated.
I keep getting the following error:
Error: document.forms.sec11_A has no properties
with this script:
function checkform(btntype)
{
|
by: RommelTJ |
last post by:
Hi,
My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the internet.
When I run Firebug on it, it says:
document.getElementById("TICKER") has no properties
TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
Here is the complete script:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |