1

I have simple element:

<a id="a1" href="#" style="position:absolute; top:0; left:0; nav-index:1; nav-down:#b1; nav-right:#a3; nav-left:#a1; nav-up:#a1">A1</a>

How to dynamically change nav-index and nav-up only ?

1
  • 2
    Is it possible to move those inline styles to a separate style sheet? Commented Feb 25, 2012 at 13:05

4 Answers 4

4
document.getElementById('a1').style.navIndex = newIndex;
document.getElementById('a1').style.navUp = newValue;

Note that as per this and this, nav-index and nav-up are only supported by Opera.

Sign up to request clarification or add additional context in comments.

Comments

3

[2023] See this Stackblitz snippet

Like this:

var a1 = document.getElementById('a1');
a1.style['nav-index'] = /* somevalue */;
a1.style['nav-up']    = /* somevalue */;
// or (style properties with hypens must be converted
// to a camel case representation for use in 'dot notation')
a1.style.navIndex = /* somevalue */;
a1.style.navUp    = /* somevalue */;
// and to retrieve the original values:
a1.style['nav-index'] = '';
a1.style['nav-up']    = '';

Furthermore it's advisable to move the inline styling to a class in a css file.

.a1nav {
 position:absolute;
 top:0;
 left:0;
 nav-index:1;
 nav-down:#b1;
 nav-right:#a3;
 nav-left:#a1;
 nav-up:#a1;
}

Comments

0

create a new css and call them using like this

function changeClass (elementID, newClass) {
    var element = document.getElementById(elementID);

    element.setAttribute("class", newClass); //For Most Browsers
    element.setAttribute("className", newClass); //For IE; harmless to other browsers.
}

Comments

-1

You can use jquery to change nav-index and nav-up.

$('a#a1').attr('nav-index', '2'); //If you want to change it to 2.
$('a#a1').attr('nav-up', '#5'); //If you want to change it to #5.

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.