views:

28

answers:

1

I have the following snippet of code on a page that I need to specifically target the number inside the b tag and put that number in a variable. I do not have direct access to this code or I would put and ID there. There are more than one td and b tags on the page but only one font size"3". What would be the correct selector to target this text?

<td><font size="3"><b>3947</b></font></td>

This is the code I have so far but it returns other bold text on the page

<script type="text/javascript" language="javascript">
$(document).ready(function(){
var invoice_number = $("td b").text();
alert(invoice_number);
});
</script>
+2  A: 

Use an attribute equals selector, like this:

$(document).ready(function(){
  var invoice_number = $("td font[size='3'] b").text();
  alert(invoice_number);
});

You can give it a try here.

Nick Craver
lol i had it backwards I tried this but didn't work var invoice_number = $("td b font[size=3]").text();
that worked, thanks Nick, always coming through for me!!!!
@user357034 - welcome :) - If you have control over it, I'd look at changing the markup, giving the cell itself a class, less markup and an easier selector :)
Nick Craver
I wish I did but unfortunately no I have no access to the markup
@user357034 - I figured that was the case given the `<font>` tag in the first place, oh well, sorry!
Nick Craver