• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Newbie coding Javascript problems

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First post here!

I'm trying to play around with some code.
I have actions done on a class item - some simple animation where the object follows the mouse.
Just to experiment, I change to an ID and use the same code. Doesn't work.
What am I doing wrong?

Excerpt of the code:

In the Javascript I have this:

When I try console.log("CIRCLE"); I get null.

What am I doing wrong?

ASIDE... let's say I have HTML page. And I want to identify object that I can work on and manipulate... how best do I do this?

Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your selector is not correct. See this reference for selector patterns.

In general, if an element is the only one you are interested in you can use an id. If there may be more than one, use a class name.

FYI, I rarely use ids anymore; I almost exclusively use classe names as more versatile. Why did you feel the need to move from a class name to an id?
 
Omar Mi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NO Way!!!
I've been struggling with this for a few hours (how sad!!)
I was on a mission. I was going to solve.
Now works

I now have: const CIRCLE = document.querySelector('#circle');
DOH!

Why an ID? No reason! JUST - I thought... I know... I'll change the code. I'll try and 2 circles on the page. Just to give myself a challenge, make on of them be an ID.

ASIDE: let's say I have problems pinning down an object...
How do I best locate it...?
I would assume run some commands using console?
Like for this one... how could I have drilled down and located the exact object?

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could run the command in the console and check the results: document.querySelector('#circle')


P.S. Please attend to your display name issue. Thanks.
 
Omar Mi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply.
my mistake was not using #.
i kinda freaked out and was looking for a way to get any item. assume that's not really needed?

>> P.S. Please attend to your display name issue. Thanks.
i clicked on the link in the email about changing. the link page doesn't load.
i've looked manually at profile, there's nothing that allows change.
not sure what i need to do?
 
Get out of my mind! Look! A tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic