jquery - Mulitple divs/same class with different css -


i need change style of div has same class other divs. site built umbraco , don't have access html add id div trying change. structure of html looks this

<header>...</header> <div class="container">...</div> <div class="container">...</div> <div class="container">...</div> 

i need add background image 3rd div. not sure of proper way rather can done css or if it's best use javascript. tried using jquery select div index wasn't getting anywhere that. started with.

<script> $( ".container:eq( 2 )" ).css( "background", "url(/media/9165540/happy-female.jpg)" ); </script> 

i need add

background-size: cover; 

but wasn't sure how add well. appreciated. thanks

in jquery can use:

$('.container').eq(2).css({'background':'url(/media/9165540/happy-female.jpg)', 'background-size': 'cover'}); 

or add specyfic class '.container's using:

$('.container').each(function(i){ $(this).addclass('container-'+i); }); 

and styling class. or @ least can use css:

.container:nth-child(2) 

but problematic solution... because css don't change third container always, change container if in third position of it's parent. example if have this:

<div> <header>...</header> <footer>...</footer> <div class="container">...</div> <div class="container">...</div> </div> 

and want select second container must do:

.container:nth-child(4) 

because second container in fourth position relative parent.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -