Reputation: 300
I have system generated anchor tag and it doesn't contain id or class. Only thing I know that it has fixed inner html(like "Clear"). Can we access this anchor tag with inner html. So on click of this I can hide another div tag.
.wrap-div{
width:70px;
height:100px;
background-color:black;
}
#submit{
display:block;
position: relative;
}
<div class='wrap-div' ></div>
<div id="submit">
<a onclick="fun1();" href="javascript:{}">
Apply
</a> |
<a onclick="fun2()" href="javascript:{}">
Clear
</a>
</div>
Upvotes: 0
Views: 915
Reputation: 1
You can use attribute equals selector
$("a[onclick='fun2()']")
$("a[onclick='fun2()']").css("color", "red");
.wrap-div {
width: 70px;
height: 100px;
background-color: black;
}
#submit {
display: block;
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='wrap-div'></div>
<div id="submit">
<a onclick="fun1();" href="javascript:{}">
Apply
</a> |
<a onclick="fun2()" href="javascript:{}">
Clear
</a>
</div>
or :contains()
$("a:contains('Clear')")
$("a:contains('Clear')").css("color", "sienna");
.wrap-div {
width: 70px;
height: 100px;
background-color: black;
}
#submit {
display: block;
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='wrap-div'></div>
<div id="submit">
<a onclick="fun1();" href="javascript:{}">
Apply
</a> |
<a onclick="fun2()" href="javascript:{}">
Clear
</a>
</div>
Upvotes: 2
Reputation: 1816
Try this code in jQuery:
$('#submit a').each(function(i, item) {
if($(item).text() == 'Clear')
{
// here you have access to that a tag
console.log(item);
return;
}
});
Upvotes: 0