-1

HTML-

<div class="wrap">
    <div class="floatleft">
    <div class="JShover">
    <h3 class="border">Works with your business applications
    <p >Connect with Office 365, GSuite.</p></h3>
    </div>
    <div class="JShover">
    <h3 class="border">Works with your business applications
    <p>Connect with Office 365, GSuite.</p></h3></div>
    </div>
    <div class="floatright" >
    <img class="integration" src="integrations-image.png" width="100%" height="100px">
    </div>
    <div style="clear: both;">
</div>
</div>

CSS used for the div-

.border{
  border-left:6px solid #3793EE;
  text-align: left;
  padding-left: 5%;
  }
div.JShover{
    height:50%;
    text-align: left;
    opacity:0.5;

}
.wrap {
    overflow: hidden;
    margin: auto;
    max-width: 700px;
}
.floatleft {
    float:left; 
    width: 50%;
    height: 500px;  
}

.floatright {
    float: right;
    height: 500px;
    width: 50%;
}

When the floatleft divs JShover is clicked the opacity should be 1. Otherwise it should 0.5. JavaScript used-

 <script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
 </script>
<script type="text/javascript">
$(".JShover").click(function() {
    this.style.opacity = 1
});
</script>

In the result the JShover divs have an opacity of 0.5 (since it is in the CSS) but when I click on it, the opacity does not change to 1. Is there any error in my code or implementation?

Yohanelly
  • 69
  • 1
  • 9

2 Answers2

2

You can for example do it like this:

$(".JShover").click(function() {
    this.style.opacity = 1
});

Also add opacity: 0.5; to your div.JShover element in css.

Working fiddle here.

Edit:

First, be sure to have jQuery on your site either with having and linking a local copy or linking it inside your <head> like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

And second be sure to put your js code for changing opacity below the linked jQuery library, for example below or at the end of the <body> tag.

Luka Čelebić
  • 1,083
  • 11
  • 21
1

Here is your html

<div class='floatleft'>
Hello..... :)
</div>

Here is your CSS

 .floatleft{
    background-color:red;
    opacity:0;
    }

Here is your JS

$('.floatleft').click(function(){
$(this).css('opacity','1')
});

Hope this helps you

Liaqat Saeed
  • 428
  • 5
  • 17
  • Thank you @LSKhan, I have updated my code in the question. When i click on the text, the opacity does not change to 1. Could you please help me out? – Yohanelly Oct 08 '17 at 09:30
  • did you get you solution from @PredatorIWD? or i help you? – Liaqat Saeed Oct 08 '17 at 13:48
  • Hey, I have got it. But I am still trying to figure out how to make the previously clicked div to go back to its previous opacity of 0.3 when the next div is clicked? Code- https://jsfiddle.net/71973avt/5/ – Yohanelly Oct 08 '17 at 14:24
  • you mean you want to make the clicked element opacity 1 and others to 0.5?rite? – Liaqat Saeed Oct 08 '17 at 14:28
  • Hey I got it, figured it out. Had to add $(".JShover").css('opacity', '0.2'); Do you know how to make a good looking navigation bar at the top of the webpage? I can send you a screenshot of what I'm trying to achieve if thats okay. Thank you so much for your time :) – Yohanelly Oct 08 '17 at 14:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/156207/discussion-between-yohanelly-and-lskhan). – Yohanelly Oct 08 '17 at 14:32
  • yeah i can make it let me see your your screenshot first – Liaqat Saeed Oct 08 '17 at 14:32