Haben Sie Probleme mit diesem. Ich habe eine Seite mit mehreren Produkten, Hemden, Hosen usw. Jedes Produkt kommt in den gleichen verschiedenen Farben: schwarz, blau, grün usw. Ich versuche, einige jQuery zu schreiben, die ich für alle Produkte verwenden kann. Grundsätzlich habe ich ein div, mit allen Produktbildern mit Klassen für jedes, zum Beispiel, das schwarze Produktbild ist class = "prodblack". Ich würde gerne die gleichen Klassen für alle Produkte verwenden. Aber die Art, wie ich dieses Setup jetzt habe, wenn ich auf das blaue Farbfeld für ein Produkt klicke, zeigen ALLE Produkte das blaue an, nicht nur das Produkt, auf das ich gerade klicke.Jquery Klassen innerhalb der Eltern Div verstecken mit (this)
Hier ist ein Teil des HTML ist, ist dies nur ein div von vielen, aber sie sind alle die gleichen, gleichen Klassen, gleiche Farben usw.
<div class="fb-col-md-4 fb-col-sm-6 col-xs-12" itemscope itemtype="http://schema.org/Product">
<a href="#double_thick_blanket">
<span class="product-wrap">
<img alt="Double Thick Blanket" class="proddefault" onerror="this.onerror = null;this.src='/images/image-not-found.jpg'" src="<?php bloginfo('template_directory'); ?>/img/products/pants/pants-tan.jpg">
<img alt="Double Thick Blanket" class="prodtan" onerror="this.onerror = null;this.src='/images/image-not-found.jpg'" src="<?php bloginfo('template_directory'); ?>/img/products/pants/pants-tan.jpg">
<img alt="Double Thick Blanket" class="prodgreen" onerror="this.onerror = null;this.src='/images/image-not-found.jpg'" src="<?php bloginfo('template_directory'); ?>/img/products/pants/pants-green.jpg">
<img alt="Double Thick Blanket" class="prodblue" onerror="this.onerror = null;this.src='/images/image-not-found.jpg'" src="<?php bloginfo('template_directory'); ?>/img/products/pants/pants-blue.jpg">
<img alt="Double Thick Blanket" class="prodgray" onerror="this.onerror = null;this.src='/images/image-not-found.jpg'" src="<?php bloginfo('template_directory'); ?>/img/products/pants/pants-gray.jpg">
<img alt="Double Thick Blanket" class="prodblack" onerror="this.onerror = null;this.src='/images/image-not-found.jpg'" src="<?php bloginfo('template_directory'); ?>/img/products/pants/pants-black.jpg"></span>
<span class="productSwatches">
<span class="squareSwatch blue"></span>
<span class="squareSwatch gray"></span>
<span class="squareSwatch tan"></span>
<span class="squareSwatch green"></span>
<span class="squareSwatch black"></span>
<span style="clear:both"></span>
</span>
<section class="price-wrap">
<h4 class="new-tree"><span itemprop="name">Double Thick Blanket</span> <em>$99.95</em></h4>
</section></a>
</div>
Und hier ist die JQuery eingerichtet, I mit $ (this) begann mit den blauen swatch messing, aber kann nicht scheinen, um es zu bekommen arbeiten:
jQuery(document).ready(function($){
var hideAllButBlue = ".prodgreen,.prodtan,.prodblack,.prodgray,.proddefault";
var hideAllButBlack = ".prodgreen,.prodtan,.prodblue,.prodgray,.proddefault";
var hideAllButGreen = ".prodblack,.prodtan,.prodblue,.prodgray,.proddefault";
var hideAllButTan = ".prodblack,.prodgreen,.prodblue,.prodgray,.proddefault";
var hideAllButGray = ".prodblack,.prodgreen,.prodblue,.prodtan,.proddefault";
$(".prodgreen,.prodtan,.prodblue,.prodblack,.prodgray").hide();
$(".proddefault").show();
$(".blue").click(function() {
$(this).parent('div').show('.prodblue');
$(hideAllButBlue).hide();
});
$(".black").click(function() {
$('.prodblack').show();
$(hideAllButBlack).hide();
});
$(".gray").click(function() {
$('.prodgray').show();
$(hideAllButGray).hide();
});
$(".green").click(function() {
$('.prodgreen').show();
$(hideAllButGreen).hide();
});
$(".tan").click(function() {
$('.prodtan').show();
$(hideAllButTan).hide();
});
});
Jede Hilfe wäre sehr dankbar, danke