I am using jQuery to check if an element is odd or even:
$("#map183").parent().is(':even');
This will return true or false depending on where the element is.
However this will always return false:
function whereAreWe(myself,range){
var parent = myself.parent();
var position = parent.is(':even');
alert(position);
//outputs false
}
$('.hasSVG').on('click', function(){
whereAreWe($(this),2);
});
I have the working example here: JSFiddle
In the example you will see that i am trying to see if the parent(.line) of said element is either odd or even.
This is because the :even selector is only useful within a list but parent refers to exactly one object. Therefore, :even with a list of 1 does not make sense.
However, you have IDs that indicate the line-number
var position = parent.attr("id").substr(4) % 2 == 0;
console.log(position);
extracting the id and deleting the "line"-string from "lineX" gives you the line-number X. A check with MOD 2 (or alternatively a bitwise AND with 1:)
var position = ((parent.attr("id").substr(4) & 1) == 1);
will do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With