user3086226
user3086226

Reputation: 93

How can I change div inner HTML font size?

I have a <div> element. In this <div> there is a <table> and <span> elements. And the <span> does not have a html id attribute.

I want to change font-size in the <span>. Can I do it with javascript or jQuery?

I try change class and directly give property with CSS, but they are not working.

How can I change font size?

my <div class="xxx">

and in the style

 .xxx  {
background-image:url('../k_g.png');
cursor: pointer;
background-repeat: no-repeat;
background-position: center 0%;
font-size:40px;
}

Upvotes: 0

Views: 4773

Answers (5)

Tor-Erik
Tor-Erik

Reputation: 1000

If you span is not a direct child of the div with the class you could do

 .xxx span {
     font-size: 40px;
 }

However this will affect all spans inside the div and can have unforeseen consequences in the future.

Upvotes: 2

gacon
gacon

Reputation: 2135

The first I wonder if this div with .xxx class was create before you call your script or not? If it's ok so just run this script in document.ready function in jQuery:

$(".xxx").css({font-size:"30px"});
or jQuery.noConflict();jQuery(".xxx").css({font-size:"30px"}); 

instead of you run some libraries using the same $ for that script.

Upvotes: 1

Chethan N
Chethan N

Reputation: 1158

Use:

$("div.xxx").children("span").css( "font-size", "30px" );

Upvotes: 1

Raja Asthana
Raja Asthana

Reputation: 2100

You can apply the below CSS,

.xxx > span  {
    font-size:40px;
}

Upvotes: 2

Anoop Joshi P
Anoop Joshi P

Reputation: 25527

try

$(document).ready(function () {
        $(".xxx").css("font-size", "200%");
    });

Upvotes: 1

Related Questions