1

Is there something in jQuery to uniquely identify a DOM node, if the HTML markup does not provide an id, i.e. if $(NODE).attr("id") returns undefined?

Goal: exclude a specific node of a specific class.

jQuery(document).ready(function($){
$(".accordion-right-content").hide();
    $(".article-image img").click(function() {
    $(".accordion-right-content").each(function(i,v) {
        // the following comparison does not work because of the missing ID
        if ($(v).attr("id") !== $(this).parent().parent().children(".accordion-right-content").attr("id")) {
            $(v).hide();
        } else {
            $(v).show();
        }
    });
});

Except the specific $(this).parent().parent().children(".accordion-right-content") to be hidden before shown again.

Stefan
  • 137
  • 13

1 Answers1

0

You should use not operator like this:

if (!$(NODE).attr("id")){
//do stuff here
}

And the following, you're having wrong:

if ($(v).attr("id") !== $(this).parent().parent().children(".accordion-right-content").attr("id")) {

Should be this:

if ($(this).attr("id") !== $(this).parent().parent().children(".accordion-right-content").attr("id")) {
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231