I have a div filled with spans that don't have an id on them, and need to be able to determine if one of those spans is marked(highlighted). My approach at first was the following:
function isSelected(element){
var selectedElement = window.getSelection().anchorNode.parentNode;
if($(selectedElement).index() === $(element).index()){
// It's selected
}
}
But this solution doesn't consider cases where other elements from another div are selected that have the same index.
I tried comparing the element objects like this:
$(selectedElement).get() == $(element).get()
and like this:
$(selectedElement) == $(element)
but the comparison was always returning false.
How do I determine if they're the same without giving every span an id?
Solution:
if(selectedElement.isEqualNode(element){
}