tags:

views:

440

answers:

4

i have div

 <div style="height:100px; width:100px" class="total-title">
first text
</div>

and i have jquery statemtnt to chnage its value

   $('div.total-title').html('test');

not working

Thanks

+1  A: 

To put text, use .text('text')

If you want to use .html(SomeValue), SomeValue should have html tags that can be inside a div it must work too.

Just check your script location, as farzad said.

Reference: .html and text

MaLKaV_eS
+1  A: 

try $('div.total-title').text('test');

Aliixx
+2  A: 

if your value is a pure text (like 'test') you could use the text() method either. like this:

$('div.total-title').text('test');

anyway, about the problem you are sharing, I think you might be calling the JavaScript code before the HTML code for the DIV is being sent to the browser. make sure you are calling the jQuery line in a <script> tag after the <div>, or in a statement like this:

$(document).ready(
    function() {
        $('div.total-title').text('test');
    }
);

this way the script executes after the HTML of the div is parsed by the browser.

farzad
+1, html also should do the job. Correcting my answer
MaLKaV_eS
not working ...
air
+2  A: 

You have referenced the jQuery JS file haven't you? There's no reason why farzad's answer shouldn't work.

GenericTypeTea