Last active
August 29, 2015 13:56
-
-
Save Greg-Boggs/9275906 to your computer and use it in GitHub Desktop.
Using jQuery with Drupal 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
Drupal.behaviors.myBehavior = { | |
attach: function (context, settings) { | |
$("body").click(function() { | |
alert("Hello World"); | |
}); | |
} | |
}; | |
})(jQuery); |
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);
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);
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
(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
}
};
})(jQuery);