Reputation: 643
I am building an anchor tag dynamically through my code.
str += " <li><a href='" + hyperlink + "'>" + linkName + "</a></li>";
I want to apply the below style to this anchor tag on a particular condition.
style="pointer-events: none;cursor: default;"
If (somecond) { apply the above style to anchor tag }
Please suggest how to achieve this.
Thanks in advance.
Upvotes: 0
Views: 4577
Reputation: 840
You can do like this.
If(Your Condition Matching Criteria)
{
$("li a").css("pointer-events","none");
$("li a").css("cursor","default");
}
but above solution will do this for all the page level anchor who is in 'li' tag so what you can do for specific parent element of li you can provide unique identifier and then can do like this.
If(Your Condition Matching Criteria)
{
$("#uniqueParentId li a").css("pointer-events","none");
$("#uniqueParentId li a").css("cursor","default");
}
Replace "uniqueParentId" with your provide unique parent Id value.
Upvotes: 1
Reputation: 258
$("a").css("pointer-events","none");
$("a").css("cursor","default");
Hope this is may stisfy you
Upvotes: 0
Reputation: 4427
Use the jquery .css()
function (see docs), for example:
if(somecond) {
$('a').css({
"pointer-events": "none",
"cursor": "default"
});;
}
Upvotes: 1