Hi
I have a site where I need to check all href-links if they are in a custom dictionary on the site. If they exist then the title attribute in the a-tag should be set to the text that is fetched from the server. I put this together based on other wuestions from this site (example, not tested):
// How to only activate "a href" links?
jQuery('a').mouseover(function() {
// should be what is between <a href="">this text</a>. Is this correct?
var dictionaryWord = jQuery(this).text();
// do a server site call to get description for the word given in the var above
jQuery.get("/getDescriptionFromDictionaryWord.aspx", { word: dictionaryWord },
function(data){
// set title tag for the a-tag actual a-tag
// will "this" refer to the a-tag with mouseover?
jQuery(this).attr("title", data);
});
});
There may be errors in the above. I have just created it from different answers found in this here on StackOverflow. Is there a better way to do get a response from a server than the above?
If it works I only need a nice way to show the title tag on mouseover. I have seen some packages for that so that should be easy enough.
BR. Anders
UPDATE (based on answers below)
// all "a href" do this for the first mouseover "one.()"
jQuery('a[href]').one('mouseover',(function() {
// get a reference to the clicked + get dictionary word
var anchor = jQuery(this),
dictionaryWord = anchor.text();
// do a server site call to get description for the word given in the var above
jQuery.get("/getDescriptionFromDictionaryWord.aspx", { word: dictionaryWord },
function(data){
// set title tag for the a-tag actual a-tag
// will "this" refer to the a-tag with mouseover?
anchor.attr("title", data);
});
}));