I have the feeling I’m doing dirty code, although it works fine…
How could I replace those IF statement by regular JQuery selectors in such case:
see code + fiddler
<html>
<body>
<a href="#b" class="cssPauseAll" historyID="12">Pause All</a><br/>
<a href="#b" itemHistoryID="12" ContentID="45">AA</a><br/>
<a href="#b" itemHistoryID="12" ContentID="14">BB</a><br/>
<a href="#b" itemHistoryID="12" ContentID="78">AA</a><br/>
<a href="#b" class="cssPauseAll" historyID="13">Pause All</a><br/>
<a href="#b" itemHistoryID="13" ContentID="45">BB</a><br/>
<a href="#b" itemHistoryID="13" ContentID="14">BB</a><br/>
<a href="#b" itemHistoryID="13" ContentID="78">CC</a><br/>
</body>
</html>
$(document).ready(function () {
$(document).on("click","a.cssPauseAll[historyID]", function () {
var historyID = $(this).attr("historyID");
//alert("historyID from PauseAll " + $(this).attr("historyID"));
$(document).find("[itemHistoryID]").each(function() {
var itemHistoryID = $(this).attr("itemHistoryID");
if(historyID == itemHistoryID)
{
alert($(this).attr("ContentID"));
}
});
});
});
You can concatenate the strings:
http://jsfiddle.net/FBCBP/
Please note that there is no need to select the document object and use the
findmethod. You can select the element using$orjQuerydirectly and also using attribute selector alone is very slow, you can use element selector before attribute selector(in this casea).