I would like to add CSS to an HTML Element dynamically using Prototype JS. I am using below code.
var wrapper_content = $('wrapper').innerHTML;
wrapper_content.img.setStyle({display:'inline'});
But this is not working.
In cases like these you can use the invoke() utility method like so
$$('#wrapper img').invoke('setStyle',{'display':'inline'});
http://api.prototypejs.org/language/Enumerable/prototype/invoke/
You could change your selector to var wrapper_content = $('wrapper img');
And then you can do like this wrapper_content.each(function(el) { el.setStyle({ 'display': 'inline' }); });
Edit: Changed the syntax to work with Prototype JS instead.
getElementById. Try var wrapper_content = $$('#wrapper img');.Ive been using a combination of Geek Num 88 and T Gibbons answers for a few years. its a combination of css selectors and setting the style display value is more obvious.
$$('#wrapper img').each(function(name) {
name.style.display = "inline";
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/prototype/1.7.3/prototype.js"></script>
<div id="wrapper">
<img style="display: none;" src="https://cdn0.iconfinder.com/data/icons/free-business-desktop-icons/128/Home.png" />
</div>
.innerHTMLjust return the html inside thewrapper-element (which isn't a HTML-element). Try withconsole.log($('wrapper'));and see if it returns anything at all. Otherwise, you might have to check your selector.console.log($('wrapper'));and I can see the HTML element at console..innerHTMLis returning HTML content of that element. But I would like to apply css on Images ofwrapper_content. How can I do that ??