I’m working with Jquery in Drupal.
I have sets of four blocks that all share a common title, Trying to set Jquery to hide the second, third, fourth blocks when the first is clicked.
Here’s the code:
javaScript:
(function($){
$('.view-display-id-block_1').delegate('a','hover',function(){
var linkText = $(this).text();
var viewSelectString= '.views-field-title:contains('+linkText+')';
var textSelect = $('p,li,a,span',$(viewSelectString));
var recordString = 'div.views-field-title:contains('+linkText+')';
var recordStringRefine = 'li .views-row:has('+recordString+')';
var recordStringSelect = $(recordStringRefine);
$recordStringSelect.hide();
});
})(jQuery);
HTML:
<li><p class='views-field-title'>contains linkText</p><p></p><p></p></li>
<li><p class='views-field-title'>contains linkText</p><p></p><p></p></li>
<li><p class='views-field-title'>contains linkText</p><p></p><p></p></li>
<li><p class='views-field-title'>contains linkText</p><p></p><p></p></li>
Using delegate() because the jQuery version is too old to support on()
So the first half of the query works fine, I can select any element within the four blocks.
Each block has a number of elements, I want to go up a level, find the parent <li> that contains each block, and hide that.
When I add the recordString stuff, my query stops working. All the has() examples I can find only select by element.
In-context there’s a lot of other classes and elements floating around, but basically I need to select elements based on whether they include ‘linkText’, then somehow travel up the tree to the wrapper li and hide that (and hopefully everything that it contains).
Can’t find much info on whether has() supports pseudo-selectors and all that, in any case it seems like its starting to get kind of complicated and confusing. Definitely can’t make the code run. Is this just the wrong way to get this done?
Thanks, I appreciate the help
The solution may be as simple as this: