user1448093
user1448093

Reputation: 157

javascript and css styling

Basically i just want to have padding to the left and not all around on this code:

if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
  document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
  document.getElementById("livesearch").style.border="1px solid #000";
  document.getElementById("livesearch").style.background="#FFF";
  document.getElementById("livesearch").style.padding-left="10px";    
}

But i don't know the syntax as padding-left breaks the argument. Is there a better way to do this without using a CSS as there are different styles depending on the if/else statements?

Upvotes: 1

Views: 98

Answers (4)

SANA
SANA

Reputation: 689

its always good to catch your variables on top as well,

var liveSearch = document.getElementById("livesearch")
liveSearch.style.paddingLeft = "10px";

Upvotes: 1

Moataz Elmasry
Moataz Elmasry

Reputation: 2519

There's a reference that explains which javasceript term corresponds to which css. like this This page

But generally its a good practice to use css whenever possible. This separation between javascript and css is recommended.

Upvotes: 0

Yash Dayal
Yash Dayal

Reputation: 1174

Try this: document.getElementById("livesearch").style.paddingLeft="10px";

Upvotes: 3

allen213
allen213

Reputation: 2277

In native js you want paddingLeft not padding left

document.getElementById("livesearch").style.paddingLeft="10px"; 

Upvotes: 3

Related Questions