Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change font size of all elements inside a div

I have following page in which there is a div menu. Inside menu we can have <table>, <p>, <h>. Different elements for example:

<div id="menu">
 <p>abc def</p>
 <table>
  <tr><td>helloo </td><tr>
  <tr><td>hiii </td><tr>
 </table>
 <div id="sub"><p>123 this is test</p></div>
</div>

Is there a way to change size of all text in between elements inside menu. For example: abc def, hellooo, hiii, 123 this is test. Can i change all that text using jquery or javascript some how.

like image 722
NoviceMe Avatar asked Mar 01 '12 19:03

NoviceMe


People also ask

What is the font size of text inside DIV HTML element?

Note that in HTML the default font size is 16px.

How do I apply a font to all elements in CSS?

Add the CSS * (asterisk) selector to select all the elements of the document. Set the font-size, font-family, line-height, and color properties.

How do you change the font size in an element?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.


1 Answers

Yes you can use JavaScript and or jQuery to do what you want, but why wouldn't you just use CSS like suggested?

or you can try this:

<Style>
    /*Assumed everything is inheriting font-size*/
    #menu{
      font:12px;
    }
    /* Force all children to have a specified font-size */
    #menu *{
      font:14px;
    }
</style>

<script>
    //JavaScript
    document.getElementById('menu').style.fontSize = "14px";
    //jQuery
    $("#menu").css({'font-size':'14px'});

</script>
like image 199
Eric Hodonsky Avatar answered Sep 18 '22 09:09

Eric Hodonsky