Log in

View Full Version : how to target image with css



jundo12
01-21-2016, 02:32 AM
i have a javascript that calls an image. is there a way with css to change the parameters (width and height) of that image if the only place the image is mentioned is inside the javascript?

p.s. wasn't sure if this was a css question or a javascript question. lol

Beverleyh
01-21-2016, 06:03 AM
You'd target it the same way as if the image was in HTML - Apply a class to the image, then use that class as a selector in the stylesheet.

jundo12
01-22-2016, 03:37 PM
but the image is only being called inside the javascript. how do i apply a css class inside a javascript? these are two different languages

Beverleyh
01-22-2016, 04:12 PM
You can apply a class in JavaScript in a few ways;


document.getElementById("myelement").classList.add("myclass"); /* IE10+ http://caniuse.com/#feat=classlist */


document.getElementById("myelement").className += " myclass"; /* note the space in case there are other classes */

with jQuery;
$("#myelement").addClass("myclass");

jundo12
01-23-2016, 06:11 AM
thanks bev!

Beverleyh
01-23-2016, 07:49 AM
You're welcome :)