Adding feedback buttons

I have 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 add (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 div [title] into theme?

Example

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

      

I want two buttons located immediately after the div is closed:

<div title="Foo">
...
</div><a href="me@host?subject=Foo">feedback</a>
<div title="Bar">
...
</div><a href="me@host?subject=Bar">feedback</a>

      

0


a source to share


2 answers


$(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 a feedback link after the DIV you should use .after () instead of .append ()

+1


a source


You will need to use .each

to iterate like this:



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

      

+1


a source







All Articles