views:

39

answers:

3

i used this line of code but it didn't work

$("a#link").attr("href",$(this).attr('tempref').val());
+1  A: 

When you call:

$(this).attr('tempref')

that returns a value that is not the jquery object so you can not add .val() after that and you cannot refer to the object with this. If you want to assign the value to the href attribute you must do:

$("a#link").each(function(){
    $(this).attr("href",$(this).val());
})

If you don't want to do this, try to explain better your question.

mck89
thanks it help me so much
GOM3A
@gomaa, if this answer helped you out, you can click on the tick over to the left there to show this is the accepted answer.
nickf
A: 

You don't need to call val():

$("a#link").attr("href", $(this).attr('tempref'));
Zed
A: 

thanks all i used this code and it works fine

        $("a").each(function(){
    if($(this).attr('tempref')!=null)
{     var tempref= $(this).attr('tempref');}
     if(tempref!=null)
{    $(this).attr('href',tempref);  }
})
GOM3A