JavaScript Get Attributes of window.getSelection().anchorNode

Since textNodes do not have any attributes you will have to get the attributes from the element parent. The select event has spoty support so I used the mousedown event and registered the Document Object to listen for it. In order to control where and when you get values from among 100 possibilities (remember the Document Object will be aware of mousedown event on anything but the Window Object), we must establish 2 things:

  1. Event.currentTarget: A property of the Event Object, that represents the element registered to the event. In the Demo e.currentTarget is the Document Object (document.)

  2. Event.target: A property of the Event Object that represents the origin of an event, which is fancy talk for the element that was clicked, changed, hovered over, etc. In the Demo e.target is basically anything in the document.

The following Demo demonstrates a way to get the id and/or classes of a clicked element node.

Demo

Details are commented in Demo

document.addEventListener('mousedown', showAttr, false);

function showAttr(e) {
  // if the node clicked is NOT document...
  if (e.target !== e.currentTarget) {
    /* if the clicked node has a class attribute...
    || log all of its classes in console
    */
    var tgt = e.target;
    if (tgt.hasAttribute('class')) {
      var cList = tgt.classList;
      console.log('class=' + cList);
    }
    /* if the clicked node has an id...
    || log its id in console
    */
    if (tgt.hasAttribute('id')) {
      console.log('id=' + tgt.id);
    }
  }
  return false;
}
.as-console-wrapper {
  width: 30%;
  margin-left: 70%;
  min-height: 100%;
}

main,
main * {
  outline: 1px solid black
}
<main id='base'>
  <h1 class='mainHeading'>Title</h1>

  <ol class='ordered list'>
    <li class='1'>One</li>
    <li class='2'>Two</li>
    <li class='3'>Three</li>
  </ol>
  Text
  <article id='post31' class='test'>
    <h2 class='postHeading'>Title</h2>
    <p class='content text'>Post content</p>
    article text
  </article>
</main>





</main>
Answer:1

I have a form and wanted to retain its values when form loads without using any web storage. I want to use only Javascript or jQuery. Moreover, I want that form values such as radio and dropdown ...

I have a form and wanted to retain its values when form loads without using any web storage. I want to use only Javascript or jQuery. Moreover, I want that form values such as radio and dropdown ...

  1. retain form values after submit javascript
  2. retain form values after back button
  3. retain form values after submit php
  4. retain form values after submit
  5. retain form values after submit jsp
  6. retain form values after submit html5
  7. retain form values after submit mvc
  8. retain form values after submit jquery
  9. retain form values after submit django
  10. codeigniter retain form values
  11. struts2 retain form values
  12. html form retain values after submit
  13. spring mvc retain form values
  14. how to retain form values after refresh php
  15. how to retain form values after submit in spring mvc
  16. how to retain form values in jsp
  17. how to retain form values after submit in struts
  18. php form retain values

What is the most efficient way to check a certain condition on every element of an array and return false if one or more elements do not meet the condition, for example, I have this array for example ...

What is the most efficient way to check a certain condition on every element of an array and return false if one or more elements do not meet the condition, for example, I have this array for example ...

  1. check every element in list python
  2. check every element in array javascript
  3. check every element in array java
  4. check every element in numpy array
  5. check every element matrix matlab
  6. check every element in array python
  7. check every element in array php
  8. js check every element in array
  9. matlab check every element
  10. how to check every element in array

It works but I don't understand what the hell I did, I need to know if the "js", "css" properties is what the task looks for??? module.exports = function(grunt) { grunt.initConfig({ concat: { ...

It works but I don't understand what the hell I did, I need to know if the "js", "css" properties is what the task looks for??? module.exports = function(grunt) { grunt.initConfig({ concat: { ...

  1. grunt js files

I'm reading JSON from a third party URL. In that JSON data I found this timestamp starttime: 1522899000000 (on 4/5/2018 -> 5th April 2018)...I thought that it is Unix timestamp and tried to convert ...

I'm reading JSON from a third party URL. In that JSON data I found this timestamp starttime: 1522899000000 (on 4/5/2018 -> 5th April 2018)...I thought that it is Unix timestamp and tried to convert ...

  1. what timestamp format is this
  2. what is timestamp format in sql
  3. what is timestamp format in oracle
  4. what is timestamp format in java
  5. what is timestamp format in hive
  6. what is timestamp format in php
  7. what is unix timestamp format
  8. what is utc timestamp format
  9. what is default timestamp format in hive
  10. what is the default timestamp format in oracle
  11. what is timestamp(6) format in oracle