Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get number from string

I'm trying to use jQuery to pass a height to colorbox. Doing so, the only way I can think to define the height is through the links 'class'. So I'm trying to figure out how to get the number from a string; e.g;

class="height_900" ; I want it to get the number, '900'.

Is this possible with jQuery?

MORE INFO: Ok.. So here's what I'm trying to achieve.

I'm creating a Wordpress Shortcode for colorbox (variation of lightbox). Colorbox sets its height and width via jQuery.

The Wordpress shortcode contains the attributes 'height' & 'width' that allow the user to set both manually if they wish. The problem is, I cannot figure out a way to pass these PHP variables to the colorbox jQuery.

The best solution I could come up with was to have a class that goes as follows: height_$height; e.g. height_450. I then wanted to get just the number via jQuery, then it uses that as that specific colorbox's height. Same for the width.

like image 469
Matthew Ruddy Avatar asked Feb 10 '26 22:02

Matthew Ruddy


1 Answers

try this:

parseInt( className.split('_')[1] );
like image 68
Jean Louis Avatar answered Feb 13 '26 13:02

Jean Louis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!