Add inline style using Javascript
nFilter.style.width = '330px';
nFilter.style.float = 'left';
This should add an inline style to the element.
How to set inline CSS of element to default using javascript?
You can get inline CSS in style
attribute of element using getAttribute()
and store it in variable and on check/uncheck of checkbox insert and remove it from style
attribute
var checkBox = document.querySelector('#form input[name=termsCheckBox]'),
terms = document.getElementById('termsText'),
style = terms.getAttribute('style');
checkBox.addEventListener('click', function(){
if (checkBox.checked)
terms.style.cssText = "color:black; font-weight:normal";
else
terms.style.cssText = style;
});
<form id="form">
<input type="checkbox" name="termsCheckBox">
<textarea id="termsText" style="color:red; font-weight:bold">termsText</textarea>
</form>
Using javascript to add inline css style with height dynamically calculated from container width
Why not try to enforce and aspect ratio with a pseudo element (in this case a :before
). As long as no other content is inside your .entry-thumbnail-wrap
- because the pseudo element will fill the aspect ratio you want and push everything else out of the way.
.entry-thumbnail-wrap {
background-size: cover;
background-position: center;
height: auto;
}
.entry-thumbnail-wrap:before {
content: '';
width: 100%;
/* This will give it an aspect ratio of 2/1 */
padding-bottom: 50%;
display: block;
}
<div class="entry-thumbnail-wrap" style="background-image: url(http://placehold.it/300x300)"></div>
Related Topics
Scraping JavaScript Website in R
How to Communicate Between Related React Components
Difference Between Domcontentloaded and Load Events
Run Greasemonkey Script on the Same Page, Multiple Times
Node.Js - How to Set Environment Variables in Code
Change the Selected Value of a Drop-Down List with Jquery
Prevent Browser Caching of Ajax Call Result
Graph Visualization Library in JavaScript
Chrome Doesn't Delete Session Cookies
How to Set a Cookie for Another Domain
Rails 4 Turbolinks Make Form Submit Multiple Times
Mocha/Chai Expect.To.Throw Not Catching Thrown Errors
Find by Key Deep in a Nested Array
How to Round to 1 Decimal Place in JavaScript