Bujji
Bujji

Reputation: 1727

Jquery - .text() , .html() not working on IE8

Here is the code and jsfiddle link . I tried .text and .html both functions. But both not working on IE8. Could any one provide me the solution for IE ? ( I googled and people seems to have similar kind of problems , but couldn't get solution) Thank You

http://jsfiddle.net/3eaGL/

  <div class="controls">       
            <div class="btn-group" data-toggle="buttons-radio">
                <input name="MySecurity[my_education]" id="MySecurity_my_education" type="hidden" value="0" />                            
                <button type="button" class="btn" value="2" display="Private">P</button>
                <button type="button" class="btn" value="1" display="Friends">F</button>
                <button type="button" class="btn" value="0" display="All ( Public )">A</button>
            </div>   
            <text class="mySecurityDisplay"></text>  
       </div>  




$("button[display]").bind('click', function(){
                    var buttonValue=this.value;
                    $(this).siblings("input[type=hidden]").val(buttonValue);
                    $(this).parent().next().text($(this).attr( 'display' ));
                 });

Upvotes: 4

Views: 7338

Answers (4)

Netorica
Netorica

Reputation: 19327

Ok I got it working the problem was the <text> element

http://jsfiddle.net/3eaGL/7/

the Jquery created an instance object after selecting the <text> element but because its not a valid HTML tag, the Jquery object will not return any methods for your disposal.

Its like your trying to do a val() to a <span> element but is only valid in html form elements.

Upvotes: 1

Ram
Ram

Reputation: 144689

The issue is this:

<text class="mySecurityDisplay"></text>  

IE8 doesn't render unknown tags, therefore jQuery doesn't select your element, the issue is not related to html or text method. Use a valid tag instead and your code will work.

Upvotes: 7

Techie
Techie

Reputation: 45124

  1. Check whether you have valid html, There could be mismatched tags.

  2. Try using append instead of the html method.

Upvotes: 0

bukart
bukart

Reputation: 4906

Your problem is the <text> tag. This isn't a valid HTML tag. IE below version 9 interpretes unknown tags in this way: <text class="mySecurityDisplay"></text> will become <text class="mySecurityDisplay"/><text/> an so you can't insert any content inside it.

Just write <div class="mySecurityDisplay"></div>, this will work.

Upvotes: 4

Related Questions