Search code examples
javascriptjqueryjavascript-frameworkunobtrusive-javascript

JavaScript passing dynamic value in class issue in IE 7 only


I am facing an issue in IE7 only while passing an a dynamic value to javascript. as shown below. this work in all browsers except IE 7.

$val =$id.$i;
echo "<a href='javascript:void(0);' id='network' class=$val value='$octet'>+".$octet.".0.0.0</a> <br />"; 

I am capturing this value in javasript as show below

$(".msg_body #network").click(function(){
    var network = $(this).attr('value');
    alert(network); // alert fails in IE 7

    var clsName = $(this).attr("class");
    alert(clsName); // alert fails in IE 7

complete php code below

<?php 
                $octets = $this->Ip;
                $octetets = $this->octent1;
                $i= 1;
                $id='network';
                foreach($octetets as $octet){
                    $val =$id.$i;

                    echo "<a href='javascript:void(0);' id='network' class=$val value='$octet'>+".$octet.".0.0.0</a> <br />";
                    value='$octet'>+".$octet.".0.0.0</span> <br />";
                    $i++;

                }

            ?>

Solution

  • Try this:

    $(".msg_body").on('click', '#network', function(e){
        e.preventDefault();
        var network = $(this).attr('value');
        alert(network); // alert fails in IE 7
    
        var clsName = $(this).attr("class");
        alert(clsName); // a
    });