javascript - Changing the background-image -


could tell me have change here able change background-image via javascript?

$(document).ready(function(){       $('p').css('background-image', 'url("misc/bilder/2.png")');  });
.p {      height: 100%;      width: 100%;      position: relative;      padding: 25%;      background-size: cover;      background-attachment: fixed;      -webkit-transition: 0.2s ease;      -moz-transition: 0.2s ease;      transition: 0.2s ease;      background-image: url("misc/bilder/1.png");      }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <p>      text  </p>

thanks!

in css you're referencing .p class in javascript you're referencing p element. might help:

$(document).ready(function(){      $('.p').css('background-image', 'url("misc/bilder/2.png")'); }); 

updated: question updated after answer. remove . .p in css. so:

css:

p {     //some css } 

javascript:

$(document).ready(function(){      $('p').css('background-image', 'url("misc/bilder/2.png")'); }); 

html:

<p>  text </p> 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -