JavaScript HTML/Javascript scope html javascript scope,html javascript scope variable

I have been fiddling around with HTML lately and I have a question.

Is there a way to scope element's id as a child of another element? It's difficult to describe, but here's an example.

<body>
  <div id="a">
    <div id="inner"></div>
  </div>
  <div id="b">
    <div id="inner"></div>
  </div> 
</body>

I do not know if this is legal (since "inner" is declared twice), but the problem is as follows:

Suppose I have a webpage full of square divs with their own styles and fixed positioning (kinda like Windows 8 metro), I would like to be able to group all components of a particular square into that square, so that I can use javascript to focus on the elements in the scope of say, in pseudocode.

ClickMeButtonDiv.ClickMeButton.value = parseInt(ClickMeButton.value) + 1;

In short, I want to know if it is possible to group all children of a div to that div, because if I have 100 squares on one page doing their own thing, it is a headache to keep all elements by id bound to global scope...

Is there any way to accomplish this?

Thanks ahead of time!

Answer:1

You can't have non-unique IDs. You can use the class property though. Change id="inner" to class="inner" and if you're using JQuery, you could try using child selectors. For example:

$("#a > .inner");

Without jQuery

document.getElementById('a').getElementsByClassName('inner')[0];
Answer:2

How do I redirect the user based on two options on drop down menu's? i have read a few similar questions but couldnt relate the advice as the form code I am using is very long and complicated. I have ...

How do I redirect the user based on two options on drop down menu's? i have read a few similar questions but couldnt relate the advice as the form code I am using is very long and complicated. I have ...

  1. form redirect based on input

I am making a rich text editor with UIWebview, which uses a contentEditable div. I want to get the caret's position in pixels. I have searched a lot, and I got the code below. function ...

I am making a rich text editor with UIWebview, which uses a contentEditable div. I want to get the caret's position in pixels. I have searched a lot, and I got the code below. function ...

  1. caretaker
  2. carethy
  3. caretaker jobs
  4. caret symbol
  5. carethy reviews
  6. caretracker
  7. caret browsing
  8. caretaker synonym
  9. caretaker definition
  10. caretenders
  11. caretaking
  12. careta
  13. caretrust reit
  14. caret r
  15. carettas
  16. caretrust reit stock
  17. caretaker gazette
  18. caretaker witcher 3
  19. carethy hand sanitizer
  20. caretech

I am trying to query the user twice (more than once in general), but everything gets printed out together and the first response get processed by both functions. I believe this has to do with the ...

I am trying to query the user twice (more than once in general), but everything gets printed out together and the first response get processed by both functions. I believe this has to do with the ...

  1. multiple prompts for user input python
  2. multiple prompts for user input

I have a RabbitMQ consumer listening to a queue in RabbitMQ and receiving event data in NodeJS. I would like to have the consumer send each data event to AWS Redishit (possibly using their JavaScript ...

I have a RabbitMQ consumer listening to a queue in RabbitMQ and receiving event data in NodeJS. I would like to have the consumer send each data event to AWS Redishit (possibly using their JavaScript ...