In an HTML
document, the dynamic generation of divs and buttons using JavaScript
can be seen in the code snippet below.
<div style="background: rgb(247, 247, 247);">
<button class ="xyz" disabled="disabled">Button1</button>
</div>
<div style="background: rgb(247, 247, 247);">
<button class ="xyz" disabled="disabled">Button2</button>
</div>
<div style="background: rgb(247, 247, 247);">
<button class ="xyz">Button3</button>
</div>
The challenge is to change the css(background color)
of only the last div
where the Button is not disabled. Attempts made with jQuery resulted in changing the css for all divs above it. A solution involving either jQuery or JavaScript is sought to specifically target the last relevant div element.
$(".xyz").parent().css({ "background": "rgb(95, 49, 49)" });