Skip to content

Instantly share code, notes, and snippets.

@Greg-Boggs
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Greg-Boggs/9275906 to your computer and use it in GitHub Desktop.
Save Greg-Boggs/9275906 to your computer and use it in GitHub Desktop.
Using jQuery with Drupal 7
(function($) {
Drupal.behaviors.myBehavior = {
attach: function (context, settings) {
$("body").click(function() {
alert("Hello World");
});
}
};
})(jQuery);
@docans
Copy link

docans commented Feb 28, 2014

(function($) {
Drupal.behaviors.myBehavior = {
attach: function (context, settings) {

$(document).ready(function() {
// check to see if the li tag with css classes .first .last has the text 120V in it

   if ($(".first.last").text() == "120V"){

   //if true hide the block
       $("#block-views-accesories-view-block-1").hide();
    }
   else {
   //if false show the block
        $("#block-views-accesories-view-block-1").show();
    }       
  });  

}
};
})(jQuery);

@docans
Copy link

docans commented Feb 28, 2014

Modified to this without any succes

(function($) {
Drupal.behaviors.myBehavior = {
attach: function (context, settings) {

// check to see if the li tag with css classes .first .last has the text 120V in it

   if ($(".first.last").text() == "120V"){
   console.log
   //if true hide the sidebar-second
       $("#block-views-accesories-view-block-1").hide();
    }
   else {
   //if false show the sidebar second
        $("#block-views-accesories-view-block-1").show();
    }       

}
};
})(jQuery);

@TwoD
Copy link

TwoD commented Feb 28, 2014

Try this:

(function($) {

Drupal.behaviors.myBehavior = {
  attach: function (context, settings) {
    // check to see if the li tag with css classes .first .last has the text 120V in it
    if ($(".first.last", context).text() == "120V") { // Sure this selector is targeting the right element?
      //if true hide the sidebar-second
      $("#block-views-accesories-view-block-1", context).hide();
    }
    else {
      //if false show the sidebar second
      $("#block-views-accesories-view-block-1", context).show();
    }
  }
};

})(jQuery);

@docans
Copy link

docans commented Feb 28, 2014

Solutions

(function($) {

Drupal.behaviors.myBehavior = {
attach: function (context, settings) {
// check to see if the li tag with css classes .first .last has the text 120V in it

if (/120V/.test($('.first.last', context).text())){ 
  //if true hide the sidebar-second
  $("div#sidebar-second").hide();
}

// else {
//if false show the sidebar second
// $("div#sidebar-second").show();
// }
}
};

})(jQuery);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment