Get numeric value of webkit filter property with jQuery

$(".content").css("-webkit-filter")

Return :

"opacity(0.46) grayscale(0.7)"

How can i get only this value : 0.46 ?

Problem courtesy of: wawanopoulos

Solution

DEMO

var regExp = /\(([^)]+)\)/;
var str = regExp.exec("opacity(0.46) grayscale(0.7)");
var modified = str[0].substring(1).slice(0, -1);
console.log(modified);

RegExp was taken from here

Solution courtesy of: martynas

Discussion

you could use regex ( http://jsfiddle.net/Wn2Yk/ ):

var cssStyle = $(".content").css("-webkit-filter");
var regExp = /opacity\(([^)]+)\)/;
var matches = regExp.exec(cssStyle);

console.log(matches[1]);

Discussion courtesy of: Cristi Pufu

Refer this Fiddle

Fiddle

$(".content").css('opacity')

Discussion courtesy of: Arunkumar

This recipe can be found in it's original form on Stack Over Flow .

我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章