0

Am trying to add an attr for the id and onclick, its working on firefox and chrome but for some reason it isn't working on IE 9 . Any alternative or something is wrong with me code?

$(".extendedGridView tr td a").each(function (index) 
{
   if ($(this).html() == "Update") 
   {
       $(this).attr('id', 'insertButton');
       $(this).attr('onclick', "return Validate('extendedGridView')");
   }        
});
3
  • Can you try by changing .html() to .text() Commented Nov 9, 2012 at 12:14
  • its entering the if since i tried an alert and its working Commented Nov 9, 2012 at 12:15
  • why are you assignin same id to all links in that td and freebird is right. Commented Nov 9, 2012 at 12:16

1 Answer 1

6

Don't use attr for this. Use

 this.id = 'insertButton';
 $(this).click(function(){return Validate('extendedGridView')});

Note also that checking a text using html() isn't going to work if there are returns or space or any tags. Prefer this test :

if ($(this).text().trim() == "Update") {

Then, be sure to have a different id for each element. It's unclear in your code if you're OK on this point but as you're using each, I'm afraid it's not. If what you need is to make your elements selectable more easily, use a class :

$(this).addClass('update');
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.