72422

How to read from CSS files with jQuery

Ok, I have a HTML page with jQuery included.

I have a CSS file with a good load of lines in, I would like to read all styles for a given element from the external CSS file... Not the inline styles...

I have the following code (which looks like it should work...):

var styleProperties= {}; var getCssProperties = ['width', 'margin', 'height']; for (c=0;c<=returnStyleProps.length;c++) { styleProperties[returnStyleProps[c]] = $('div#container').css(returnStyleProps[c]); alert(styleProperties); } alert(styleProperties);

But this only seems to alert:

"[Object Object]"

<strong>[edit] Please...? I'm really quite stuck, nothing seems to work :( [/edit]</strong>

Answer1:

var cs = {}; var elem = $('h1')[0]; for(var s in elem.style) { // console.log(s + typeof(s)); var v = $(elem).css(s); if (v && v != '') { cs[s] = v; } } for(var s in cs) { console.log(s + ': ' + cs[s]); }

please run in firebug if you have h1 element on the page and jQuery is used... just a rough idea though...

Answer2:

to start, please try console.log(styleProperties); and look at what the object holds in firebug console...

Answer3:

Using firebug put a breakpoint on the code and you will be able to inspect the properties of said object. That should let you know what it is and if it is what you want.

Recommend

  • Bundled scripts not working MVC
  • css Star-rating html
  • How to align an image side by side with a heading element?
  • Access object instance inside an event handler
  • PayPal API Listener Website Payments Standard URI
  • C# - Most efficient way to iterate through multiple arrays/list
  • How to load gif image while ajax content is loading and javascript [duplicate]
  • Use tryCatch within R loop
  • converter json to two dimensional array
  • Can I read an iPhone beacon with Windows.Devices.Bluetooth.Advertisement.BluetoothLEManufacturerData
  • Ajax Upload File: $_FILES is empty but files exists in request header
  • Appending Character to Character Array In C
  • How to convert workspace coordinates to screen coordinates?
  • How can I extract results of aggregate queries in slick?
  • Declaring variable dynamically in VB.net
  • How do I alternate colors in Flat List (React Native)
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • AES padding and writing the ciphertext to a disk file
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Unanticipated behavior
  • Comma separated Values
  • retrieve vertices with no linked edge in arangodb
  • How to delete a row from a dynamic generate table using jquery?
  • Acquiring multiple attributes from .xml file in c#
  • using HTMLImports.whenReady not working in chrome
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • apache spark aggregate function using min value
  • How can I remove ASP.NET Designer.cs files?
  • EntityFramework adding new object to nested object collection
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal
  • How to load view controller without button in storyboard?