-1

I’m in my _Layout.cshtml page. I’m trying to manipulate my menu bar using css and jquery.

Here’s what I’m trying to do.

<script type="text/javascript">
$(document).ready(function () {
    var varElement = document.getElementsByTagName("var");
    for (var i = 0; i < varElement.length; i++) {
        varElement[i].style.fontSize = ".75";
    }
});
</script>

My problem is when I get to varElement[i]. I expected to see style in my intellisense but style is not in the list of properties. The only items available in the intellisense list are:

Constructor
hasOwnProperty
isPrototypeOf
propertyIsEnumerable
toLocalString
toString
valueOf

How do I get JQuery to access my css style?

Zach Lysobey
  • 14,959
  • 20
  • 95
  • 149
CloudyKooper
  • 727
  • 3
  • 19
  • 47
  • Most likely problem?... The intellisense is imperfect. Don't rely on it. When you *run* the code, is there an error? Unexpected behavior? Visual Studio has gotten a *lot* better with JavaScript in recent versions (2012/2013), but it's not ideal just yet. – David Apr 22 '14 at 17:10
  • If you are just trying to change font size, please see this answer: http://stackoverflow.com/questions/3236511/set-font-size-in-jquery#answer-3236532 –  Apr 22 '14 at 17:11
  • And dont forget to add a unit to `.75`. Like `px`, `pt`, `%` ... – phylax Apr 22 '14 at 17:12
  • possible duplicate of [Changing CSS style using jquery](http://stackoverflow.com/questions/17768142/changing-css-style-using-jquery) – T J Apr 22 '14 at 19:01

2 Answers2

1

In jQuery you can set CSS style as below:

$('var').css('fontSize', .75)

$('body').css('background', '#f00');
Manoj Yadav
  • 6,560
  • 1
  • 23
  • 21
-1

You'll want to use the .css() method. I'm not sure how you're using the for loop in your example, but on the jsfiddle is an example that includes a simple for loop, and hopefully that is helpful.

var changeStuff = function(){
for(i=1;i<=2;i++){
$('#p'+i).css('font-size','3em');

} };

http://jsfiddle.net/6UtyN/1/

Matt West
  • 1,376
  • 1
  • 12
  • 18