Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change visibility of a div css to visible with jQuery

Tags:

I have NEXT and PREVIOUS buttons on my screen. When the page initially loads I want the Previous button to be hidden and as soon as user clicks the Next button I want Previous button (div tag to be visible). I have a CSS property for Previous button where I am setting the visibility value to False. And also an if statement where I check to see if page counter is greater than 1 then change the visibility of navigationButtonTop to true. It is not working..what am I doing wrong !?

$(function() {
  $("#navigationButtonTop").css("visibility", "visible");
});
div.navigationButtonTop {
  visibility: hidden;
  height: 100px;
  width: 100px;
  background-color:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="navigationButtonTop"></div>
like image 464
HereToLearn_ Avatar asked Jul 15 '15 15:07

HereToLearn_


People also ask

How do you make a Div visible in jQuery?

Projects In JavaScript & JQuery To toggle a div visibility in jQuery, use the toggle() method. It checks the div element for visibility i.e. the show() method if div is hidden. And hide() id the div element is visible. This eventually creates a toggle effect.

How do I set visibility visible in jQuery?

jQuery. fn. visible = function() { return this. css('visibility', 'visible'); }; jQuery.

How do you make a Div visible in JavaScript?

Another way to make a div visible or invisible is with the display property. Then we can make it visible with: const div = document. querySelector('div') div.

Is jQuery hide () is equivalent to?

jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page).


2 Answers

firstly you have not closed your if statement and navigationButtonTop is a class not a id try this.

if (that.get("pageCounter") >= 1) {
     $(".navigationButtonTop").css("visibility", "visible");
}

as the OP has edited his question the new answer would be:

$(function() {
  $(".navigationButtonTop").css("visibility", "visible");
});
like image 170
Josh Stevens Avatar answered Oct 02 '22 12:10

Josh Stevens


First of all, the code of how you actually like to trigger the event, would be nice to know. Maybe the trigger is not working at all?

Additionaly you addressed differently. In CSS navigationButtonTop is a class (see the ".") and in JS it's an id (see the "#"). Is this the culprit in your atual code? If not I'll assume it's an id further...

For more readability try to move your visibility: hidden to an extra hidden class. So you just can trigger:

$("#navigationButtonBottom").on('click', function() {
  $("#navigationButtonTop").removeClass('hidden');
});

And in you HTML add the class hidden to your button

#navigationButtonTop.hidden { visibility:hidden; }

Or do it using javascript:

jQuery(document).ready( function($) {
  $("#navigationButtonTop").addClass('hidden');
})
like image 40
Seika85 Avatar answered Oct 02 '22 14:10

Seika85