views:

139

answers:

2

I've a static html file that is generated from docbook5 sources. Now I need to add feedback buttons, at the end of each section, so I'm appending (using jQuery) a link after each title:

$(document).ready(function() {
    $("div[title]").append('<a href="mailto:me@host?subject=XXX">feedback</a>');
})

how to insert the div[title] into subject?

EXAMPLE

<div title="Foo">
...
</div>
<div title="Bar">
...
</div>

I want two buttons placed right after the closing div:

<div title="Foo">
...
</div><a href="me@host?subject=Foo">feedback</a>
<div title="Bar">
...
</div><a href="me@host?subject=Bar">feedback</a>
+1  A: 
$(document).ready(function() {
   $("div[title]").each(function(){
     $(this).append('<a href="mailto:me@host?subject='+encodeURIComponent(this.title)+'">feedback</a>');
   });
})

BTW. if you want to insert the feedback link after the DIV, you should use .after() instead of .append()

Rafael
Thanks very much :-)
dfa
+1  A: 

You will need to use .each to iterate through like so:

$("div[title]").each(function() {
    $(this).append('<a href="mailto:me@host?subject=' + $(this).attr("title") + '">feedback</a>');
});
ern
Thanks very much :-)
dfa