How to display results of a query with alert message


I’m relatively new to jQuery, and I don’t understandy why the following doesn’t work. Hopefully, you can enlighten me.

I declared a variable:
var currHive = $(“#masterHive”) .find(“div.currentHive”);

Now I want to see if the query returned the correct element id. So, I tried each of the alert messages shown below, one-at-a-time. This is the strategy I am using to verify the code; i.e. do something, then tell me what I did.

var currHive = $(“#masterHive”) .find(“div.currentHive”);

	alert(currHive).attr(id);	/* returns object Object */
	alert(;		/* returns undefined */
	alert(;		/* returns undefined */
	alert($(this).attr('id'));	/* returns undefined */


Note: I have successfully used — alert($(this).attr(‘id’)); — in an experiement to tell me which button was clicked, in a statement using the .bind() method.

Thanks for the feedback.

The alert didn’t work because of error in code. It should be …


Thanks for the reply, Semantic7.

Your solution was close, very close, but it didn’t work.
So, I took your suggestion and tried a couple ideas, one of which worked.

alert(currHive.attr(id)); this didn’t work
alert(currHive.attr(‘id’)); I added quotations around the id and it worked.

This stuff drives me nuts sometimes… a parenthesis here, a quotation there… you miss one, or have where there shouldn’t be any, and the whole thing fails.