0

What I'm trying to do grab the tabIndex from this line:

<input name="110" title="" id="test" style="position: absolute; top: 155px; left: 687px; tabindex: 3; z-order: 99;" type="checkbox" CHECKED="checked" runat="server" value="on"/>

And have it set as an HTML attribute via javascript.

How can I achieve this?

Ideally what I'm looking to see is this:

 <input name="110" title="" id="test" tabindex= "3" style="position: absolute; top: 155px; left: 687px; ; z-order: 99;" type="checkbox" CHECKED="checked" runat="server" value="on"/>
13
  • you cant use jquery ?? Commented May 5, 2015 at 14:33
  • only if its jQuery 1.0. Its to run on IE 8 Commented May 5, 2015 at 14:34
  • With access to jquery, you can use $("SELECTOR").attr("tabindex") = "desired index" Commented May 5, 2015 at 14:35
  • You have some errors in your inline CSS: tabindex = 3 and z-order Commented May 5, 2015 at 14:37
  • The above was taking from a page with a tonne of check boxes in it. But I'll look into the z-order thing. Commented May 5, 2015 at 14:39

2 Answers 2

0

tabIndex is not a style property it should be out side style attribute.

To get tabIndex

var x = document.getElementById("test").tabIndex;  

To Set tabIndex

document.getElementById("link3").tabIndex = 6;
Sign up to request clarification or add additional context in comments.

Comments

0

While I have no idea why you would have a tabindex set in the style, which isn't legal syntax, you can get it through a regex.

var elem = document.getElementById("myInput");
var match = elem.getAttribute("style").match(/tabsize\s*:\s*(\d+)/);
if(match) {
    elem.setAttribute("tabindex", match[1]);
}

Working demo: http://jsfiddle.net/0syvw3Lo/1/ Note that this only works if that was set inline, not with a CSS sheet.

2 Comments

The above code is generated in a really convoluted way and this is the issue I'm trying to fix. I'd thought moving the css out of the style part and into a new attribute would easy.
@Sean Well what we're saying is that tabindex isn't CSS at all. It's an error to have it in the style attribute in the first place. That's why it's hard to retrieve it.

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.