vektor vektor - 1 year ago 88
Javascript Question

Find elements where name is different than id using jQuery

How do I write jQuery expression that will find inputs where the

attribute value is different from the
attribute value?

This should be found

<input name="foo" id="bar" />

This should not be found

<input name="foo" id="foo" />

Trivial stuff like
fails, because the
expression expects a constant on the right hand side.

Answer Source

You can do this using filter() function. And use trim to make sure.

Edit Simple version

    return !=;

If there are any issues because of trailing or leading spaces, then the following can be used.

    thisID = $.trim(;
    thisName =  $.trim(;
    return thisID != thisName;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download