I’ve a tmp variable. If a tag id contains tmp string want to addClass. How to do?
$(document).ready(function () {
var tmp = "#lnkPage" + id;
$("#pageingdiv").children().each(function (n, i) {
var id = this.id;
//if (id.contains(tmp)) {
// $(id).addClass('box');
//}
});
});
<div id="pageingDiv">
<a id="CPH_Content_C002_lnkPage1" ></a>
<a id="CPH_Content_C002_lnkPage2" ></a>
<a id="CPH_Content_C002_lnkPage3" ></a>
<a id="CPH_Content_C002_lnkPage4" ></a>
</div>
</div>
Look at the Attribute starts with, Attribute ends with and Attribute contains Selectors. They will help you select all the elements you want directly without the need to call any other functions than
.addClass(). 🙂