Reputation: 342
My task is very simple. I just want to compare two DOM Elements, like this:
HTML:
Are you a : Client <input id="client" name="cli_employ" type="radio" />
Employer <input id="employ" name="cli_employ" type="radio" />
And my comparsion with jQuery:
$("input[name=cli_employ]").on("click", function() {
// I'm sure my selector is working
if ($(this) == $("#client")) { // How to compare?
// do something
}
if ($(this) == $("#employ")) { // How to compare?
// do something
}
How can I compare those elements with the 'if' command? I just tried .is() and it always returns false. Thanks in advance.
Upvotes: 0
Views: 49
Reputation: 133403
You can use .is()
Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.
Code example
if($(this).is("#client")){
//Do something
}
Upvotes: 0
Reputation: 1040
Did you try this way?
$("input[name=cli_employ]").on("click", function() {
// I'm sure my selector is working
if ($(this).attr("id") == "client") { // How to compare?
// do something
}
if ($(this).attr("id") == "employ") { // How to compare?
// do something
}
Upvotes: 1