Change css style z-index in Javascript

If you don’t want to use a Javascript framework for some reason feel free to use native syntax of the language to change css style:

var el = document.getElementById('element-id');
var zIndex = el.style.zIndex; // get value
el.style.zIndex = 5; // set value

Anyway if you have linked jQuery in the html-page you can use framework’s method, like:

var $el = $('#element-id');
var zIndex = $el.css('zIndex'); // get value
$el.css('zIndex', 5); // set value

I’d prefer jQuery, prototype or other frameworks for these purposes but sometimes you can’t use them because of customer’s requirements or weight of the page.

Books to read

Leave a Reply

Your email address will not be published. Required fields are marked *