0

I have to change a display: none; to a display: block. I'm having troubles and I can't get it to work..

I have to change this:

.colorbox #content,.colorbox #nav,.colorbox #header,
.colorbox #service,.colorbox #footer,
.colorbox #disclaimer{display:none}

with JQuery to a display: block.

Actually I have to change it only in the ID #footer.

I tried with:

$('.colorbox #content,.colorbox #nav,.colorbox #header, .colorbox #service,.colorbox #footer, .colorbox #disclaimer').css('style', 'display: block !important');

or with:

$('.colorbox #content,.colorbox #nav,.colorbox #header,.colorbox #service,
 .colorbox #footer,.colorbox #disclaimer').css("display", "block !important");

or with:

$('#footer').css("display", "block !important");

I'm actually loading a css file from a external website.. (HTML also) Is it possible, that I can't access with a single JQuery method to this files to change their values ?

How can I make it ?

9
  • $('#footer').hide(); why not jquery? Commented Aug 17, 2015 at 7:27
  • What do you mean why not Jquery ? I'm trying with JQuery.. lol Commented Aug 17, 2015 at 7:28
  • Basically In-line styles will have more priority than the id selector. So your code should also works. I am not sure what have you done in a crack pottery way to make this code not working. Please refer this sample fiddle. jsfiddle.net/hxwx2g97 It is also same like your case. Commented Aug 17, 2015 at 7:32
  • Do you have multiple html tag with same ID ? Commented Aug 17, 2015 at 7:37
  • As the code you show should work it probably means that your selectors are wrong (please show us the relevant minimal reproducible example html), or you're using jQuery before you've included the jQuery library, or haven't wrapped the jQuery in a $(document).ready(); or equivalent. Commented Aug 17, 2015 at 7:38

3 Answers 3

1
$("#id").css("display", "none");
$("#id").css("display", "block");

or

$('#id').hide();
$('#id').show();

or

$("#id").css({display: "none"});
$("#id").css({display: "block"});

For class you can give it as:

$(".class").css("display", "none");
Sign up to request clarification or add additional context in comments.

2 Comments

But this is what I was trying actually? Why is my code not working?
I don't think you have to pass it as .colorbox #content.. try it directly as $('#content').css("display","block");
1

You can do it many ways. The following are four easy way:

  1. By using only jQuery:

$("#footer").hide();

  1. Add a class name in CSS and then use addClass with jQuery.

CSS:

.force_hide{
    display: none !important;
}

jQuery:

$("#footer").addClass('force_hide');
  1. Use style instead of css:

$("#footer").style('display', 'none', 'important');

  1. And if you want to use css then use it like following:

$("#footer").css("cssText", "display: none !important;");

3 Comments

@RajaprabhuAravindasamy I can't understand your question. Could you please describe a little bit more?
Though OP's code is a kind of trashy one, still it has to work. There's no errors/no mistakes in his code. Then why it is not working? Adding a class will not answer solve his problem. If his code doesn't works, then yours also wont work in his environment.
@RajaprabhuAravindasamy with css in jQuery he used !important, which is only problem I think.
0

If your #footer has style display: none, than use:

$( "#footer" ).css( "display", "block" )

And remove important tag from css as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.