Lill Lansey
Lill Lansey

Reputation: 4915

event.target on ie 8

jquery newbie here.

Is there a problem using event.target in ie8?

It seems to be working in ie9 and on my android.

This is my code:

 <script type="text/javascript">
   $(function() {
       $('#myMenu')[0].onclick = function(event) {
       var selected = event.target.innerHTML;
       var url = 'RedirectMenu.aspx?val=' + selected;
       location.href = url;
       }
   });
 </script> 

The html is

 <ul id="myMenu">
 <li><a href="#">Generic Clinical Tasks</a></li> 

 <li><a href="#">Facility</a>   
    <ul class="level2">
     <li><a href="#">Change Facility or Unit  </a></li> 
     <li><a href="#">Edit Facility nformation</a></li>  
     <li><a href="#">Doctors</a></li>
     <li><a href="#">Nurses</a></li> 
    </ul>
</li>

 <li><a href="#">Patient</a>   
    <ul class="level2">
etc...

To clarify - as I said I am a newbie. This is how I was able to get the item selected, not just that one of the menu items was clicked.

How am I supposed to do this using jquery?

Right now, the value of 'selected'

var selected = event.target.innerHTML;

is Doctor, when the Doctor menu item is clicked.

Upvotes: 0

Views: 1525

Answers (2)

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

Since you are using jQuery. You can bind click event like below,

   $(function() {

       $('li', $('#MyMenu').click(function(event) {
          var selected = $(this).text(); // event.target.innerHTML;
          var url = 'RedirectMenu.aspx?val=' + selected;
          location.href = url;
       });
   });

Upvotes: 2

prashanth
prashanth

Reputation: 2099

You can use jQuery for click handling. Showing your html would help better answer your question.

$("#myMenu").click(function() {
  var url = 'RedirectMenu.aspx?val=' + $(this).html();
  location.href = url;
});

Upvotes: 0

Related Questions