jQuery चयनकर्ता अब मिलेगा मैं निम्नलिखित अवधि - जावास्क्रिप्ट, jquery, एचटीएमएल को हटाना चाहता हूँ

I have been able to remove the word "Departments" using jQuery but I now want to remove one of the ">" characters that has been left behind in the HTML code inside some

<span> > </span>

where it puts out "Home > > Dog" I want to remove one of the ">"

I am unsure how to ask jQuery to ignore or remove the two lines of HTML above a selector?

$(function() {
$("a[title*="Categories"]").hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="sitemappath">
<span><a href="#" title="Home">Home</a></span><span> &gt; </span><span><a href="/allcategories.aspx" title="Categories">Departments</a></span><span> &gt; </span><span><a href="/dog/g7.aspx" title="Dog">Dog</a></span><span> &gt; </span><span><a href="/dog/food/g8.aspx" title="Food">Food</a></span>
</div>

उत्तर:

उत्तर № 1 के लिए 1

आपके बाद .hide() आप जोड़ सकते हो .parent().next("span").hide(). It will remove the span after your a[title*="Categories"]

$(function() {
$("a[title*="Categories"]").hide().parent().next("span").hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="sitemappath">
<span><a href="#" title="Home">Home</a></span><span> &gt; </span><span><a href="/allcategories.aspx" title="Categories">Departments</a></span><span> &gt; </span><span><a href="/dog/g7.aspx" title="Dog">Dog</a></span><span> &gt; </span><span><a href="http://dou9070.e-retailer.co.nz/dog/food/g8.aspx" title="Food">Food</a></span>
</div>


जवाब के लिए 2 № 2

Change the selector to target parent SPAN element, then use .next() to target immediately following sibling. with it use .addBack()

$(function() {
$("span:has(a[title*="Categories"])").next("span").addBack().hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="sitemappath">
<span><a href="#" title="Home">Home</a></span><span> &gt; </span><span><a href="/allcategories.aspx" title="Categories">Departments</a></span><span> &gt; </span><span><a href="/dog/g7.aspx" title="Dog">Dog</a></span><span> &gt; </span><span><a href="http://dou9070.e-retailer.co.nz/dog/food/g8.aspx" title="Food">Food</a></span>
</div>


उत्तर № 3 के लिए 1

Add this as your first line in $(function(){ और यह काम करेगा।

$("a[title*="Categories"]").parent().next().hide();

जवाब के लिए 0 № 4

You can select both span साथ में a and next span element and hide them using.

 $("a[title*="Categories"]").parent().next("span").addBack().hide();

$("a[title*="Categories"]").parent().next("span").addBack().hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sitemappath">
<span><a href="#" title="Home">Home</a></span><span> &gt; </span><span><a href="/allcategories.aspx" title="Categories">Departments</a></span><span> &gt; </span><span><a href="/dog/g7.aspx" title="Dog">Dog</a></span><span> &gt; </span><span><a href="http://dou9070.e-retailer.co.nz/dog/food/g8.aspx" title="Food">Food</a></span>
</div>

या आप उपयोग कर सकते हैं :has() selector to select span जिसके पास है a element with specified attribute.

$("span:has(a[title*="Categories"])").next("span").addBack().hide();

$("span:has(a[title*="Categories"])").next("span").addBack().hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sitemappath">
<span><a href="#" title="Home">Home</a></span><span> &gt; </span><span><a href="/allcategories.aspx" title="Categories">Departments</a></span><span> &gt; </span><span><a href="/dog/g7.aspx" title="Dog">Dog</a></span><span> &gt; </span><span><a href="http://dou9070.e-retailer.co.nz/dog/food/g8.aspx" title="Food">Food</a></span>
</div>