How do I assign an ID using another element’s TITLE in jQuery? Will the ID change, calling the function again?
Hi, I’m trying to get a little function working (added on to jQuery’s LavaLamp plugin, actually) that will let me retrieve the TITLE value of , and make that TITLE value the value of the ID for
.
It’s really only three lines of code:
$(“li.back”).attr(“id”, function () {
var thisid = $(“a#selected”).attr(“title”);
return thisid;
})
It really seems like this should work. The problem might be its context in the plugin. LavaLamp is basically a mouseover animation menu, and I’m trying to assign a different ID to background animated DIV to correspond to which menu item it’s hovering on. Is there an easier way to do this? In jQuery, is the .attr( key, value ) attribute only meant to set an attribute that isn’t already there or will it also change the value of one that is?
Thanks!
- Category: JQuery Questions
Hi, I’m trying to get a little function working (added on to jQuery’s LavaLamp plugin, actually) that will let me retrieve the TITLE value of , and make that TITLE value the value of the ID for
It’s really only three lines of code:
$(“li.back”).attr(“id”, function () {
var thisid = $(“a#selected”).attr(“title”);
return thisid;
})
It really seems like this should work. The problem might be its context in the plugin. LavaLamp is basically a mouseover animation menu, and I’m trying to assign a different ID to background animated DIV to correspond to which menu item it’s hovering on. Is there an easier way to do this? In jQuery, is the .attr( key, value ) attribute only meant to set an attribute that isn’t already there or will it also change the value of one that is?
Thanks!
Other Questions
Login
Search
Recent Comments
- dgdg_dasdad on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Anas Imtiaz on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- David D on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Wolfman on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- TnT on Having a Jquery PHP problem?


Majid F
Posted 10 months ago
Try this:
var myli = $(‘li.back’);
var mya = $(‘a#selected’);
mya.id = mya.title;