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;", "");
You're doing it wrong.
Here is the good way :
document.getElementById("captcha").style.display='';
尝试使用:
document.getElementById("captcha").style.display='';
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/
你应该用
div.attr("style").replace();
Try this-
var divv = document.getElementById("captcha");
divv.style.display = 'block';
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;"'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.