I don't fully understand what you're trying to do/talking about. But since $("#newitem")
is an object (albeit an empty one if there's no element with that id),
is always true.
Try it:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
if ($("#newitem")){
alert('here');
}
</script>
</head>
<body>
</body>
</html>
alerts 'here'.
If your objective is to identify whether or not there's an element with that id, you can do:
Code:
if ($("#newitem").size()
)
That will only be true if there are one or more elements with an id of 'newitem'.
BTW, your usage of ^= here:
Code:
$('a[id^="edititem"]').attr("id", 'edititem' + $author_id);
looks right to me. And the whole thing should be good, assuming $author_id is defined and is a string.
Bookmarks