I need something to increment string values representing length (css margins)
the current solution is:
function incPx(a,b){
return parseInt(a) + parseInt(b) +'px';
}
incPx($(el).css('margin-left'), '10px')
but there may be a jQuery thing for that maybe? to work with other units that ‘px’
Others have already suggested
jQuery.css()‘s relative values, but keep in mind that you can easily useparseIntto convert a string like50pxto aNumber, like so:Don’t forget to pass a
radixof 10, though. More examples: Example: Using parseInt (MDN)