Reputation:
var s="attr"
var i=$(s)
// jQuery(elem).attr(attr,eval("elm"+attr));
jQuery(elem).$(s)(attr,eval("elm"+attr));//i tried this.
how to assign a variable name in the above code(in place of s) so that i need to add an attribute to the element "elem".
Upvotes: 0
Views: 1982
Reputation: 1
This will help you
Without variable
alert($('.view-character-navigation li a[href="shows/angelina-ballerina"]').attr("href"));
With variable
showurl = '/shows/angelina-ballerina';
alert($('.view-character-navigation li a[href="'+showurl+'"]').attr("href"));
Upvotes: -1
Reputation: 12182
Your code has several problems:
I'm not quite sure exactly what you're trying to do, but here's how you would use jQuery to get an element and then alter that element's attributes using jQuery's attr() method:
var myElement = $('#myElementID'); // Store the element in a variable with jQuery
$(myElement).attr('attr', 'value'); // Set/alter one of the element's attributes
Upvotes: 3