views:

71

answers:

2

Hi there, there's a list of items on a page, some blank, with one example being:

<div class="item itemask">
  <div class="tophead">
    <div class="itemnumber">30</div>

    <a class="article" href=""></a>
  </div>
  <div class="bottomhead"> points by <a class="userlink" rel=""></a> ago&nbsp;&nbsp;&nbsp; <a href="/item?id=">discuss</a>
</div>

Hence, what jQuery or JavaScript could be used to find an instance of: <a class="article" href=""> in any instance of a div class=item on the page, and then delete or hide that individual parent div of class=item which contains that piece of code?

+5  A: 
patrick dw
+1 I did not know about hide, nice!
Adam
the first option hides all items, the second options hides the bottom part of all items. see the page here, and note the two empty items at bottom: http://bit.ly/cor8dY - that's what I'm trying to hide. The problem is that it's only class items that should be hidden that have <a> inside whose anchor is blank.
Adrian33
@Adrian33 - I see what you mean. I'll update in a minute.
patrick dw
I meant specifically <a class="article"> whose href is blank - the parent div of item should be removed. - perhaps the grandparent actually. thanks.
Adrian33
@Adrian33 - You mean to remove the `div` *with* the class `item`, right? Your comment above makes it sound like you want the parent of that `div.item`, but that would be the `body` tag. Anyway, I updated my answer.
patrick dw
@patrick - the clarification is hiding everything. http://bit.ly/di7TU5. perhaps code resembling something like:var q = $(this).closest('.item'), any = q.find('.text:hidden').length > 0;q.find('.text').toggle(any).prev().toggleClass('highlightc', any);
Adrian33
All divs with class item that contain an <a class="article"> whose href is blank should be taken out.
Adrian33
@Adrian33 - I placed the update at the top of the answer. Sorry for the confusion. Copy and paste that one, and let me know. - Currently you have: `$('div.item:has(a.article)').remove();` and it should be: `$('div.item:has(a.article[href=""])').remove();​`
patrick dw
@Adrian33 - I added 2 more solutions to the top. Not sure why the first wasn't working for you. It did for me. Anyway, if the second doesn't work, the third definitely should.
patrick dw
@patrick None of those worked.If you want to try locally, dl http://bit.ly/9mcSnw and insert where it says // stack overflow insert your code here.Thank you.
Adrian33
Both of you are correct. I had an issue with either my ISP or browser, when I switched to Firefox it started working. Now it's working in Chrome.
Adrian33
+2  A: 

To hide:

$("div.item a.article[href='']").parents(".item").css('display','none');

To delete:

$("div.item a.article[href='']").parents(".item").remove();
Adam
this has no affect on the page
Adrian33
@Adrian33 - It does. It hides/deletes the `tophead` div.
Gert G
@Adrian33 - I see what you want from your link. I modified the code. Try again.
Adam
@Adam - You could get away with `parents(".item")` instead of `parent().parent()`.
Gert G
Thanks, but none of the above affect the page :( I can link to it.
Adrian33
@Adrian33 - I'm not sure why it doesn't work for you. Both of Adam's example works for me: **Hide:** http://jsfiddle.net/9F7gf/ **Remove:** http://jsfiddle.net/rPGbg/
Gert G
It may be due to the page it's on -- many items. I don't know. Maybe try a few code snippets stacked on top of each other.
Adrian33
I had an issue with my browser or ISP. Great work, however. Thank you.
Adrian33
@Gert G - Yeah, that's much better than double parents call. I edited my answer.
Adam