Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing CSS Display property based on jQuery.html()

I'm writing a simple script that detects a language and then changes the visibility of two menu items accordingly. (test site: women.semeasy.com)

Here's the code I've written:

<script type="text/javascript">
jQuery(document).ready(function(e) {


if (jQuery('#slogan').html() == 'Centro de Información'){

    jQuery('#menu-item-862').css('display', 'block !important');
    jQuery('#menu-item-743').css('display', 'none !important');

};
});
</script>

What it's supposed to do is check the slogan to see if it's in Spanish. If it is, then it hides the "En Espanol" link and displays the "In English" one...

Pretty straight forward, but it's not working :( any suggestions are greatly appreciated!

like image 278
Jake Blank Avatar asked Mar 24 '26 14:03

Jake Blank


2 Answers

Use the appropriate methods for your purpose

jQuery('#menu-item-862').show();
jQuery('#menu-item-743').hide();
like image 152
ledzep2 Avatar answered Mar 27 '26 05:03

ledzep2


You can't apply !important with jquery. You'll need to remove that. If you need !important, create a class with important and then use addClass.

like image 41
James Montagne Avatar answered Mar 27 '26 04:03

James Montagne