tags:

views:

225

answers:

3

I have the following image in a CMS that I want to hide, I dont really want to change source code but would like to hide a specific image which does not have a class applied.

Here is the HTML:

 <td class="right side">
    <a title="Show only topic 1" href="view.php?id=3&topic=1">
    <img alt="Show only topic 1" src="http://vl3.co.uk/iphone/pix/i/one.gif"/&gt;
    </a>
    <br/>
    </td>

I want to hide the <a> and the <img>, bare in mind the title and alt tag can be different so cant use that as an identifier.

I presume I could use .find() and then use .parent() to set the <a> to display: none; thus hiding the img?

Im inlcuding the jQuery library, however the CMS has YUI included out of the box so if anyone has a YUI method it would be appreicated.

+1  A: 

The jQuery method would be:

$(".right.side a:first").hide();

This gets the first <a> underneath the class="right side" element and sets it to display: none. Be sure to replace $ with jQuery if using no conflict :)

Nick Craver
Another note: The element appears multiple times on the page, so need it to find them all.
danit
@danit - If this same structure is used every time, change `:first` to `:first-child` and it'll find each `<a>` that's the first child on a `class="right side"` element. If this isn't the case...will need you to post the other examples to give a working selector for that :)
Nick Craver
A: 

If you are needing to hide the http://vl3.co.uk/iphone/pix/i/one.gif image everywhere it shows up on the page you can do this:

$("img[src*='iphone/pix/i/one.gif']").parent('a').hide();
PetersenDidIt
+1  A: 

YUI 2.x (w/ Selector)

YAHOO.util.Dom.setStyle(YAHOO.util.Selector.query(".right.side a:first"), "display", "none");

YUI 2.x (w/o Selector)

var rightSide = YAHOO.util.Dom.getElementsByClassName("right", "td")[0],
    a = rightSide.getElementsByTagName("a")[0]

YAHOO.util.Dom.setStyle(a, "display", "none");

YUI 3.x

Y.all(".right.side a:first").setStyle("display", "none");
Tivac