I have a page that displays several divs
that when clicked retrieves and displays the attributes used to create them: float
, border
, width
, and so on.
I'd like to recover classname
, but I'm not getting it.
Use or AngularJS 1.2.1.
HTML:
<h2>Clique nas DIV´s para exibir os atributos do CSS</h2>
<div id="box1">1</div>
<div id="box2">2</div>
<div id="box3">3</div>
<div id="box4">4</div>
<p class="clear"></p>
<p id="result"> </p>
Script:
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
$("div").click(function () {
var html = ["<strong>A DIV selecionada possui os seguintes atributos:</strong>"];
var styleProps = $(this).css(["classname","float", "border",
"width", "height", "color", "background-color"]);
$.each(styleProps, function (prop, value) {
html.push(prop + ": " + value);
});
$("#result").html(html.join("<br>"));
});
}//]]>
</script>