Dr Schizo
Dr Schizo

Reputation: 4352

JQuery hide span outside of div

I am trying to hide a span but having some trouble doing so. I want to get all the spans based on their for tag value and simply hide them. My question is, is it possible to get span's where there for tag equals something?

For example:

<input type="text" id="Address1" />
<span for="Address1" class="field-error">Boo</span>

<input type="text" id="Address2" />
<span for="Address2" class="field-error">Hoo</span>

JSFIDDLE

JQUERY

$("#btn1").click(function() {
    $("span.field-error").hide();
});

Thanks in advance, DS.

Upvotes: 0

Views: 213

Answers (1)

The Alpha
The Alpha

Reputation: 146191

You may try this

$("span[for='Address1']").hide();

But it's not valid for span, instead you can use data- prefix for custom attributes, like

<span data-for="Address1">some text</span>

Then, js could be

$("span[data-for='Address1']").hide();

An example.

Upvotes: 2

Related Questions