Nitish Kumar
Nitish Kumar

Reputation: 13

How to add css property to element has specific attribute using jquery?

i need to add css property in this div using jquery, but i need to use only attribute value (dashboard_1_widget_3) to add css property.

<section class="widget grid-stack-item grid-stack-item-content" widget-token="dashboard_1_widget_3">

Upvotes: -1

Views: 375

Answers (1)

Mohammad
Mohammad

Reputation: 21489

You need to use Attribute Equals Selector [name=”value”] to select element has specific attribute contain specific value. Also use .css() to add css property to selected element.

$("section[widget-token='dashboard_1_widget_3']").css("color", "red");

$("section[widget-token='dashboard_1_widget_3']").css("color", "red");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section widget-token="dashboard_1_widget_1">Section 1</section>
<section widget-token="dashboard_1_widget_3">Section 2</section>
<section>Section 3</section>

Upvotes: 1

Related Questions