[jQuery] how to find an item when you only know part of the class name

[jQuery] how to find an item when you only know part of the class name


> -------Original Message-------
> From: Jake McGraw <jmcgraw1@gmail.com>
> Subject: Re: [jQuery] how to find an item when you only know part of the class name
> Sent: Mar 02 '07 22:46
>
> You can reference any attribute using the following notation:
>
> [@attribute^=value] Starts with
> [@attribute$=value] Ends with
> [@attribute=value] equals
> [@attribute*=value] contains
>
> So for your problem...
>
> $("td[@class^=title]")
>
> Hope this helps,
>
> - jake
>
>
> On 3/2/07, [LINK: MAILTO:DALVARADO@REMANRESOURCE.COM]
> DALVARADO@REMANRESOURCE.COM <[LINK: mailto:dalvarado@remanresource.com]
> dalvarado@remanresource.com> wrote: Hi,
>
> I have a DIV whose ID I know. Within that DIV is a table with a table
> cell which either has a class beginning with the word "title" and followed
> by an integer. I would like to reference the text within that table cell.
> What is the easiest way to get a reference to this cell?
>
> Thanks, - Dave
>
> _______________________________________________
> jQuery mailing list
> [LINK: mailto:discuss@jquery.com] discuss@jquery.com
> [LINK: http://jquery.com/discuss/] http://jquery.com/discuss/
I appreciate your reply. I'm still not finding the element, and I wanted to ask what I was doing wrong. The JS is
$(document).ready(
function () {
$('a.toggleStrike').click( function() {
var parentDiv = $(this).parents("div[@id^=toc]");
alert(parentDiv[0].id);
var tdElt = parentDiv.find("td[@class^=title]");
alert(tdElt[0].id);
var textDecor = tdElt.css('text-decoration');
var newDecor = textDecor == "line-through" ? "none" : "line-through";
tdElt.css('text-decoration', newDecor);
});
}
)
and a sample HTML div would be
            <div id="toc25" class="tocItem15-2" style="display:block; margin-left:30px">
                <div style="display:block"><table>
                    <tr>
                        <td></td>
                        <td style="text-decoration:none" class="title3">Lesson 1 Core Ancient Americans</td>
                        <td><a class="readMore" href='#'>Read</a></td>
                        <td><a href='#' class="toggleStrike">Remove</td>
                    </tr>
                </table></div>
            </div>
The first alert displays the correct value, but the second alert displays a blank box and subsequently everything in the highest level table gets a strike through it when I just want this one cell.
Thanks, - Dave
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/