K
K
KRHD2015-10-21 18:28:36
css
KRHD, 2015-10-21 18:28:36

How to make jquey code apply to all objects with id #modals?

there is this code:

$( "#modals" ).click(function() {
$( ".main" ).css( "-webkit-filter", "blur(5px)" );
$( ".modalDialog" ).css( "background", "rgba(0,0,0,0.8)" );
$( "html" ).css( "overflow", "hidden" );
$( ".main" ).css( "transition", "0.5s" );
});

But only one object with id modals responds to it.
What should I do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilyusha Prokopiev, 2015-10-21
@KRHD

id is unique and should not be repeated. There is a class for this, it is used in the same way, but it can be repeated, and instead of "#" a dot is written - ".". So the code will look like this:

$( ".modals" ).click(function() {
$( ".main" ).css( "-webkit-filter", "blur(5px)" );
$( ".modalDialog" ).css( "background", "rgba(0,0,0,0.8)" );
$( "html" ).css( "overflow", "hidden" );
$( ".main" ).css( "transition", "0.5s" );
});

A
Alexander Litvinenko, 2015-10-21
@edli007

id is a unique attribute, it must not be repeated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question