Confusing issue with element identifications

Confusing issue with element identifications

I've been using jQuery in a number of different settings for just a short while in relative terms.  Recently I encountered some confusing aspects I'm hoping to have clarified.  I've done a great deal of research and trials, but haven't gotten a definitive explanation yet, so I figured I'd come to the de facto place to ask...here.

I have a plain vanilla webform.aspx and index.html page with just one <div> it's id attribute set to "mytestdiv" and that <div> has a image within its tags.  Using jQuery suchas $('#mytestdiv).toggle(); works just as I would expect.  My confusion comes in when I place this same code inside a ColdFusion based site's cfm or a DNN based site ascx extension file.  I must use the notation  $('div[id=mytestdiv]').toggle(); in either case to make the code work.  Could someone please educate me on the difference?  In either case, this behavior is exhibited using the same api base from //ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js.....Thanks in advance.

sd