Reputation: 37
I want to get attribute in class but it doesn't work
I using Django, html, php, query
<div id="yui_patched_v3_18_1_1_1556713475044_913"
class="diagram-node-task yui3-widget yui3-overlay diagram-node yui3-widget-positioned yui3-widget-stacked"
tabindex="1" data-nodeid="diagramNode_field_task923"
style="height: 70px; width: 70px; left: 441px; top: 161px; z-index: 100;">
so i do it this one
$(".diagram-node-task yui3-widget yui3-overlay diagram-node yui3-widget-positioned yui3-widget-stacked").attr('style')
and this one
$(".diagram-node-task yui3-widget yui3-overlay diagram-node yui3-widget-positioned yui3-widget-stacked").css('width')
But they are not work (they show me undefined)
I want get style like width, height in this code
Upvotes: 0
Views: 35
Reputation: 1636
For selecting a particular style
use css()
.You can use just one class to get the attribute.Hope this helps
var style = $(".yui3-widget-stacked").attr('style')
var width= $(".yui3-widget-stacked").css('width')
console.log("Style: "+style)
console.log("Width: "+width)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div id="yui_patched_v3_18_1_1_1556713475044_913"
class="diagram-node-task yui3-widget yui3-overlay diagram-node yui3-widget-positioned yui3-widget-stacked"
tabindex="1" data-nodeid="diagramNode_field_task923"
style="height: 70px; width: 70px; left: 441px; top: 161px; z-index: 100;">
Upvotes: 0
Reputation: 18975
Change to this
let style = $(".diagram-node-task.yui3-widget.yui3-overlay.diagram-node.yui3-widget-positioned.yui3-widget-stacked").attr('style');
console.log(style);
Because all classes in same div you need add query selector as .diagram-node-task.yui3-widget.yui3-overlay.diagram-node.yui3-widget-positioned.yui3-widget-stacked
let style = $(".diagram-node-task.yui3-widget.yui3-overlay.diagram-node.yui3-widget-positioned.yui3-widget-stacked").attr('style');
console.log(style);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="yui_patched_v3_18_1_1_1556713475044_913"
class="diagram-node-task yui3-widget yui3-overlay diagram-node yui3-widget-positioned yui3-widget-stacked"
tabindex="1" data-nodeid="diagramNode_field_task923"
style="height: 70px; width: 70px; left: 441px; top: 161px; z-index: 100;">
Upvotes: 0