0
var rowText = $('tbody tr:eq(2) td:eq(2)').map(function() {
return $(this).text();
}).get()[0];

window.alert(rowText);

http://jsfiddle.net/pcxx9dyy/2/

I'm specifically looking to extract the lowest price on the marketplace of an item excluding the NPC's one.

The rows are always sorted, but sometimes there are zero NPC Shop records.

1 Answer 1

1

If this table is always sorted INCR and first row always has NPC Shop records, then just fix your code like that:

$('tbody tr:eq(2) td:eq(1)')

And it works. But if rows can be unsorted, and there might be more than one, or even zero NPC Shop records, then you need more complex algo.

Update

Here is the code for "unsorted" and "any number of NPC shop records": JSFiddle

Code:

var price = null;
$("tbody tr").each(function(i,e){
    var $col1 = $(e).find("td:eq(0)"),$col2 = $(e).find("td:eq(1)");
    if ($col1.html().indexOf("NPC")===-1) {
        var rowPrice = parseFloat($col2.html().replace(",","."));
        if (!price || price.price>rowPrice)
            price = {
                name:$col1.find("a").html(),
                price: rowPrice
            };
    }
});

alert("Min price is:"+price.price+" from "+price.name);
7
  • The rows are always sorted, but sometimes there are zero NPC Shop records.
    – Emi
    Oct 1, 2014 at 5:53
  • It works! The only problem is when I visit the actual webpage and the script just seems not to load with this snippet of code in it. <script src="img.subeta.net/scripts.js?new=81" type="text/javascript"></script>
    – Emi
    Oct 1, 2014 at 6:32
  • You might need to wait for DOM (html) to be fully loaded and generated before running the script?
    – Jevgeni
    Oct 1, 2014 at 6:33
  • Yeah, that might work, but I prefer other "domReady" shortcut, provided by jQuery, like this: jsfiddle.net/pcxx9dyy/7
    – Jevgeni
    Oct 1, 2014 at 7:03
  • Also, it seem that you have exception in external script, that you've connected to JSFiddle example. It starts working if I remove it
    – Jevgeni
    Oct 1, 2014 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.