0

I want to hide a div using Javascript. Below is my div.

<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-dialog-title-dialog-message" class="ui-dialog-title"> </span>
<a class="ui-dialog-titlebar-close ui-corner-all" href="#" role="button">
<span class="ui-icon ui-icon-closethick">close</span>
</a>
</div>

I tried below javascript, but didnt work.

   $(".ui-dialog-titlebar").css('display','none');

Any idea?

4
  • 2
    wrap it in document.ready . Also you can simply use $(".ui-dialog-titlebar").hide() Commented Sep 10, 2014 at 12:08
  • please give me an example Commented Sep 10, 2014 at 12:08
  • $(document).ready(function(){$(".ui-dialog-titlebar").hide() ;}); Commented Sep 10, 2014 at 12:09
  • @SheikhSiddiquee: hide it with ID, check my answer below Commented Sep 10, 2014 at 12:14

6 Answers 6

2

you have so many ways

$(".ui-dialog-titlebar").hide();
$(".ui-dialog-titlebar").fadeOut();
$(".ui-dialog-titlebar").css('display','none !important');
Sign up to request clarification or add additional context in comments.

2 Comments

important is not needed as this will aply css inline and it has highest priority
@EhsanSajjad !important has highest priority. inline styles will not override !important.
2

That's not javascript, but jQuery:

You can simply use hide() method:

$(".ui-dialog-titlebar-close").hide(); // you can also use css() method as yours

And you need to wrap your code inside ready handler:

$(document).ready(function(){
//your code here
});

You can learn more about jQuery here.

Comments

1

Put it in document.ready():

$(function(){

 $(".ui-dialog-titlebar-close").css('display','none');

})

and you can also use hide():

$(function(){

     $(".ui-dialog-titlebar-close").hide();

})

FIDDLE EXAMPLE:

http://jsfiddle.net/qcfdLjr3/

Comments

1

ideally hiding with ID would be more flexible way.

  <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" id="hidingDiv">
        <span id="ui-dialog-title-dialog-message" class="ui-dialog-title"></span>
        <a class="ui-dialog-titlebar-close ui-corner-all" href="#" role="button">
            <span class="ui-icon ui-icon-closethick">close</span>
        </a>
    </div>

JS code for hiding:-

    $(document).ready(function() {
        $("#hidingDiv").hide();
    });

Comments

0

Try this

$(document).ready(function(){
    $(".ui-dialog-titlebar").hide();
});

Comments

0

you can use you own code as:

$(document).ready(function(){
    $(".ui-dialog-titlebar").css('display','none');

or $(".ui-dialog-titlebar").hide(); });

because before doing all there document should be ready.

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.