I am creating a bookmarklet that pulls prices from a page (like let’s say Amazon) using a regex and I would like to be able to pull additional information regarding the fontsize of each price being pulled as a way for ranking their importance.
Below is a code I have generated that isclose to what I am looking for. match() creates an array of prices and :contains goes back through and re-searches each of the found prices for their fontsize. However, this would be a problem if the same price comes up twice.
I am looking for a way to do it all in one step.
Any advice would be appreciated.
var prices = jQuery('body').text().match(/[\$€£]\s*(?:\d[\d,]*(?:\.\d+)?)/g);
jQuery.each(prices, function() {
var size = parseInt(jQuery(":contains('" + this + "')").css('fontSize'));
});
you’ve to iterate through the results of the container elements
resultsis now an array with the prices as key and all corresponding font-sizes as values of the keys