How to write css code in javascript? (Uncaught TypeError: Cannot set property “height” of undefined)
Tags: javascript,css
Problem :
How to write css code in javascript? (Uncaught TypeError: Cannot set property "height" of undefined)
javascript
document.getElementById("slideshow").getElementsByClassName("arrow").style.height = "86px";
css
#slideshow .arrow{
height:86px;
width:60px;
position:absolute;
background:url('arrows.png') no-repeat;
top:50%;
margin-top: -43px;
cursor: pointer;
z-index: 5000;
}
Solution :
The key here is the pluralisation of getElementsByClassName
- elements. This method returns an array-like object of elements, not just one element.
To apply the style to each, you need to loop through this array-like object and add the styles to each individual element returned:
var elems = document.getElementById("slideshow").getElementsByClassName("arrow");
for (var i = 0; i < elems.length; i++)
elems[i].style.height = "86px";
CSS Howto..
the logic of the thing you're trying to do is like this: DEMO $('#menu').height(0); var menuOpen=false; $('a').click(function(e){ if(!menuOpen){ $('#menu').animate({ height:100 },200); menuOpen=true; } else{ $('#menu').animate({ height:0 },200); menuOpen=false; } e.preventDefault();...
To ensure the boxes break across multiple lines, add flex-wrap: wrap; to .group {}. .group { display: flex; flex-wrap: wrap; } .group h1 { flex: 100%; /* flex: 1 1...
Only the horizontal list items should have display: inline-block, the sub-menu items remain block elements, plus the ul of the sub-menu list should have position: absolute to keep it out...
You can use some flexbox magic: #tb { display: flex; justify-content: center; } <div class id="tb"> <a href="homelink">Home</a> <a href="newslink">News</a> <a href="contactlink">Contact</a> <a href="aboutlink">About</a> </div> ...
Add class to each (here I use .tabs) divelement, it makes easy to loop over those div. Use use jquery each method to loop over all the div $('.liquid-slider .tabs').each(...
You actually have it all correct! You're just missing a little CSS. I fixed up your jsfiddle with the right stuff (a dash of position relative and absolute and a...
Add margin-top: -50px to the big div. Alternatively, you can also wrap the small divs in another div, and float that. Depends on the situation. And position: absolute, float: none...
there is no position:left. here is a possible solution for you using your actual code with background: #header div { width: 120px; height: 130px; background: url('http://lorempixel.com/120/130') no-repeat; background-size: 170px 130px;...
Simple answer. You can't. CSS selectors target Nodes, not specific letters in some text. There are small exceptions when you consider pseudo selectors, but you can't accomplish what you want...
Click on that URL. It will open the correct file to the correct line. From there you can easily see the path... However, if you mean file path, on the...
You're looking for CSS Transforms. On the website in question, this is implemented by way of .view-tenth img { /* [other directives omitted] */ transition: all 0.6s ease-in-out 0s; }...
You could use .slice() like so: Working Example 1 $(function () { $("#tabs").tabs(); $('#tabs li').slice(2, 5).css('visibility', 'hidden'); }); or :nth-child() like so: Working Example 2 $(function () { $("#tabs").tabs(); $('#tabs...
You could use pseudo-elements :before and :after to give the door some thickness. I made a rough example for you but please modify (change colors, add prefixes to the css...
Mikkel, Hi there, try using text-centerclass like this. Added to this post I have set up a Fiddle here to do what you are looking for. I wrapped the image...
Sure, you can do this if you like: http://jsbin.com/uhiyoj <!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <style> blue { color: blue } </style> </head> <body> <blue>Hello World</blue> </body> </html> But,...
Try the following code, it should work, just to make sure you use jquery plugin at once and organize it properly. <!DOCTYPE html> <html> <head> <link href="css/bootstrap.css" rel="stylesheet"/> <link rel="stylesheet"...
This may work: .border { border:2px solid #36F; position:relative; z-index:10 } .border:before { content:""; display:block; position:absolute; z-index:-1; top:2px; left:2px; right:2px; bottom:2px; border:2px solid #36F } ...
Is it possible to create a sticky sidebar that follows you down the page but which stays inside of its container element [using HTML/CSS only]? Like this: http://codepen.io/jamesdarren/full/ivmcH ......
How can I achieve that using a single CSS query? You can't, because there are no CSS selectors for comment nodes. A couple of issues with the way you're...
Extracted from this answer Microsoft introduced -ms-filter to make Internet Explorer more standards-compliant (CSS 2.1 requires vendor extensions to have vendor prefix). As the syntax of original filter property is...
Working JSFiddle. You just need to add a position attribute to your animate-flicker class in your existing css. Check my code snippet below : @ keyframes flickerAnimation { 0 %...
Materialize scss files are interrelated with each other. Means you cannot comment mixins, colors, variables and if you do so you will get errors. For all the other elements under...
You will have to do a manual check (do a search for the sprite name first, but once you have your results you will have to use pen and paper)...
It might be a little hacky but you could always apply the transition to your div on click as well. Did this pretty quick but it works. Check out the...
You can't cover IE8 in pure CSS, because it does not support neither final nor vendor-prefixed implementation. IE9 will support it just fine. You can see full support table here:...
.chapterButton:hover, .chapterButton:hover + .listHolder { position:relative; right:150px; } ...
I found the answer to fixing the width: in the css I added: iframe[id^='twitter-widget-']{ width:100% !important;} ...
There are many aspects to do. Subdomanis First of all you must use a wildcard DNS record or you have to add a DNS record for each host. So It's...
It is currently not possible to format a tooltip. An alternative solution is to use one of the many open source projects that allow for custom HTML based tooltips and...
There you go :D (this is what you can do with a few alterations to the css-trick example): Demo: http://jsfiddle.net/djnBD/ <html> <head> <meta charset="UTF-8"> <title>Fillable Beer Bottle</title> <script type="text/javascript"...