1

I'm using a twitter feed control and I'm trying to adjust the font size of one of the elements using javascript.

Here's the html snippet in question:

 <div class="twtr-hd">
     <a class="twtr-profile-img-anchor" href="http://twitter.com/pikefindotcom" target="_blank"><img src="http://a0.twimg.com/profile_images/1266884773/stock-market-chart_normal.jpg" class="twtr-profile-img" alt="profile"></a>                     
    <h3>Pikefin</h3>    
        <h4><a href="http://twitter.com/pikefindotcom" target="_blank">pikefindotcom</a></h4> 
</div>

I'm trying to change the font size of this tag:

<h3>Pikefin</h3>

Here's the Firebug output that is showing the appropriate css:

#twtr-widget-1 .twtr-doc, #twtr-widget-1 .twtr-hd a, #twtr-widget-1 h3, #twtr-widget-1 h4, #twtr-widget-1 .twtr-popular {
    background-color: #333333 !important;
    color: #FFFFFF !important;
}
index.php #4 (line 1)
.twtr-widget h3 {
    font-size: 11px !important;
    font-weight: normal !important;
}
widget.css (line 12)
.twtr-widget-profile h3, .twtr-widget-profile h4 {
    margin: 0 0 0 40px !important;
}
widget.css (line 12)

I'm using jquery to retrieve the element (disclaimer: jquery noob) which seems to work fine but then I can't figure out the syntax to set the font size. Here's what I thought the code should be:

var element = $('.twtr-hdr h3');
element.style.fontSize="17px";

But that gives me this error message: "element.style is undefined"

So I'm unsure as to exactly what object type jquery is returning. Any assistance would be much appreciated.

3 Answers 3

3

this should be,

$('.twtr-hdr h3').css("font-size", "17px");

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

4 Comments

same as 2 other answers before yours
that is because I have less then 125 reps. so I can't post another answer in 3 mins. :( Also this works!
well, someone seems to like it ;) +1
@hunter, thanks, I hope I will earn 20 more reps so I can answer fast next time.
0

You should use jQuery's .css:

$(".twtr-hdr h3").css({fontSize:"17px"});

Your code doesn't work because jQuery doesn't return the actual element, it returns an array...so:

element[0].style... //this should work too

Comments

0

You should use:

var element = $('.twtr-hdr h3').get(0); // this way you'll get the javascript object
element.style.fontSize="17px";

or:

$('.twtr-hdr h3').attr("style", "font-size: 17px"); // jQuery style

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.