1

Im using javascript to change the display of a object, there is a css class already for the same object : #id{display:none;} When i use javascript to alter display to display:block, the Display:block; appears on the object itself in the HTML. The css propertys seem to be overriding the html's propertys because it still doesnt display.
prev4.onclick = function(){ lrg.setAttribute("src", eventpic4); lefta.setAttribute("display", "block"); };

3
  • 1
    post some codes what you've tried Commented Nov 6, 2012 at 7:45
  • 1
    HTML inline styles will always take precedence over CSS styles. I recommend opening it up in Chrome's Web Developer and see what the computed styles are for the element. Commented Nov 6, 2012 at 7:47
  • 1
    @Alan unless the css style has !important. Also, there are some quirks between using actual css and html style attributes(like with and border attributes) Commented Nov 6, 2012 at 7:56

2 Answers 2

3

A good practice is to avoid manipulating styles directly in JavaScript; you can rely on classes instead and let CSS handle the styling:

<style>
  #id { display: none; }
  #id.enabled { display: block; }
</style>
<script>
  document.getElementById("id").className = "enabled";
</script>
Sign up to request clarification or add additional context in comments.

Comments

1
 document.getElementById('id').style.display = 'block'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.