0

I am using jQuery to edit html elements using .each on all off a class. If I try to log any of the attributes then I will just get "" even though I have set the attributes to something in my css file.

Why is this happening? Can the javascript file not access the css attributes?

BOBONA
  • 100
  • 12

1 Answers1

0

As I'm unclear whether you mean CSS attributes or DOM element attributes, here's an explanation for both:

To loop through some elements before reading their (in this case value) attributes, you can do this like:

$('.element').each(function(){
    console.log( $(this).attr('value') );
});

To loop through some elements before reading their CSS properties, you can do this like:

$('p').each(function(){
    console.log( $(this).css('width') );
});

Take a look at the console to see the three elements width being output: https://jsfiddle.net/nrfxn9nb/

rorymorris89
  • 1,144
  • 7
  • 14