0

I am trying to rewrite a tag using Javascript. The code looks like this

<div id="captcha" style="display: none;">
    [content]
</div>

So I am trying to rewrite the entite tag so it removes the styling

"style="display:none;" 

From the tag on pageload. I already have this code, but I cannot seem to get it to work:

var divv = document.getElementById("captcha");
divv.innerHTML = divv.innerHTML.replace("style="display: none;", "");
6
  • What's wrong with divv.style.display='';? Commented Sep 23, 2014 at 7:27
  • 1
    The style attribute is not part of innerHTML of #captcha, rather it's part of outerHTML. Commented Sep 23, 2014 at 7:27
  • Your are changing inner information (content) not style of your div block. Try .style instead, more you can read here w3schools.com/js/js_htmldom_css.asp Commented Sep 23, 2014 at 7:27
  • Style is an attribute in your div and not innerHtml Commented Sep 23, 2014 at 7:29
  • "removes the styling ... from the tag on pageload." Why not just update the file? Commented Sep 23, 2014 at 7:36

6 Answers 6

2

You're doing it wrong.

Here is the good way :

document.getElementById("captcha").style.display='';
Sign up to request clarification or add additional context in comments.

Comments

0

Try using:

document.getElementById("captcha").style.display='';

Comments

0

You are trying to change the innerHTML of the div#capthca, not the attribute called style.

var divv = document.getElementById("captcha");
divv.style.display = '';

See the fiddle here: http://jsfiddle.net/Lbx9uuLL/

Comments

0

Try this-

var divv = document.getElementById("captcha");
divv.style.display = 'block';

Comments

0

You've made some common and obvious mistake as well:

"style="display: none;"
*      *              *

(please note the 3 quote marks!)

you have to use different quote marks, like '', not "" if your content also have ""

For example (theoretically) 'style="display: none;"'

Comments

0

You should use

div.attr("style").replace();

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.