2

I want to set for each of input fields different z-index values. How I can do this with JQuery?

I want something like this:

   jQuery.each($("input[type=text]"), function (index, item) {

        item.css("z-index", index);
    });

But "item" has no css property. How to correctly iterate an array ?

HTML:

<div>
<input type="text" required class="form-control" id="Text4" placeholder="Some text"
    runat="server" />
<input type="text" required class="form-control" id="Text5" placeholder="Some text"
    runat="server" />
<input type="text" required class="form-control" id="Text6" placeholder="Some text"
    runat="server" />
</div>
1

2 Answers 2

3

item in your code returns HTML element, not jQuery object.

I would suggest you to change your code to:

$("input[type=text]").each( function (index, item) {
    $( item ).css("z-index", index);
});
Sign up to request clarification or add additional context in comments.

Comments

1

Return the CSS property value:

$(selector).css(property)

Set the CSS property and value:

$(selector).css(property,value)

Set CSS property and value using a function:

$(selector).css(property,function(index,currentvalue))

Set multiple properties and values:

$(selector).css({property:value, property:value, ...})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.