$(document).ready(function() { try { $("ul[class='leftul'] li:last-child").attr("id", "lastli"); } catch (e) { } });