2

I want take percent value property element with Jquery but I can't do it. My elements are:

<tr id="rows">
    <td style="right:0%;"></td>
    <td style="right:20%;"></td>
    <td style="right:40%;"></td>
    <td style="right:60%;"></td>
    <td style="right:80%;"></td>
</tr>

I want get right value with percent sign. I'v used below method but returned value was pixel value:

$('#rows td').last().css('right');

Console show me this 772px

A.Mokhtari
  • 451
  • 5
  • 16
money
  • 35
  • 1
  • 1
  • 4

3 Answers3

3

You cannot get the value directly using jQuery, but in your case a solution could be to parse your style attribute using a regex to match the number inside the string

var percentValue = $('#rows td').last().attr('style').match(/\d+/)+'%';

Demo fiddle

omma2289
  • 54,161
  • 8
  • 64
  • 68
  • 1
    @money, I believe Cherniv produced a better solution with his approach, you should consider marking his as the accepted answer – omma2289 Jul 28 '13 at 06:02
3

Have a look:

var c = $('#rows td').last().get(0);
console.log( c.style.right );

JSfiddle: http://jsfiddle.net/93CxA/

Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
0

Try this one:

var right = ( 100 * parseFloat($('#rows td').css('right')) / parseFloat($('#rows td').parent().css('right')) ) + '%';
A.Mokhtari
  • 451
  • 5
  • 16