Wenn ich die install_option div nur anzeigen wollte, wenn die Wörter "Apple iPad" im Titel vorhanden sind?jQuery - Anzeigen div wenn es nur zwei bestimmte Wörter
Könnte auch mit passenden tun, wenn ein Produkt ipad genannt wird (klein geschrieben) oder Ipad
<h1 id="pbtitle">Apple iPad 3</h1>
<div class="install_option" style="display:none;">
<div style="width:35%; box-sizing:border-box; float:left;">
<h3 style="font-weight:bold;">Would you like to view accessories?</h3>
</div>
<div class="apple_install_option" style="padding-top:20px;">
<a href="https://www.apple.com" target="_blank">
<img alt="Apple.com" src="http://cdn.cultofmac.com/wp-content/uploads/2012/10/lightningconnector.jpg" style="margin-right:20px; max-width:200px; height: auto;">
</a>
</div>
</div>
$(".install_option").each(function() {
var brand = $("h1#pbtitle").text().toLowerCase();
if (brand != "Lenovo") {
$('.install_option').css('display', 'block');
}
});
https://jsfiddle.net/ote8w56v/
Die jsfiddle Siehe oben funktioniert nicht gezeigt. Dieser tut: https://jsfiddle.net/54eg8cn6/ – Syno
Sie können '.indexOf' verwenden, wie [this] (https://jsfiddle.net/ote8w56v/3/) – George