Joel G Mathew
Joel G Mathew

Reputation: 8061

Proper selector for this tag?

I cant seem to find the right jquery selector for this tag:

HTML:

<div class="span4 span4-mod">
    <div class="well well-mod">
    <h4 class="DomainDescription">Iniz LAX1</h4>
    <span class="btn-block">
        <button></button>
    </span>
    <form action="pinfo.php" method="post">
        <input type="hidden" value="">
        <button>History</button>    
    </form>
    Port Status<br />
    <span class="portstatus porton">21</span>
    <table class="table" style="margin-top: 10px;">
        <tbody>
            <tr>
                <td><strong>Distro:</strong></td>
                <td class="showdistro">Debian 7.1</td>
            </tr>
            <tr>
                <td><strong>Online since: </strong></td>
                <td class="showonline">2 Days 10:29</td>
            </tr>
        </tbody>
    </table>    
</div>

I'm trying to search for the class "DomainDescription", and then search for the HTML within the class "showonline", and manipulate the latter.

I'm looking for the relationship of sibling (table) >child (tbody) > child (tr) > child (td)

Try as I may, I cant seem to find a proper selector for this kind of relationship.

I began by:

$('.DomainDescription').each(function () {                  
    var PrintedUptime=$(this).siblings().children(".showonline").html();
    alert (PrintedUptime);
});

What should the proper selector be?

Upvotes: 1

Views: 53

Answers (2)

markasoftware
markasoftware

Reputation: 12652

The correct css selector is:

.DomainDescriptor~table>tbody>tr>td>.showonline

I think that is correct, at least. Therefore, you can use:

$('.DomainDescriptor~table>tbody>tr>td>.showonline').each(function(){
    alert(this.html());
})

to achieve the desired effect. This is not tested.

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

you can

$('.DomainDescription').each(function () {                  
    var PrintedUptime=$(this).closest('.well-mod').find(".showonline").html();
    alert (PrintedUptime);
});

Demo: Fiddle

Upvotes: 1

Related Questions