Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should always cache jQuery objects with slow selectors in a variable if you are going to use them more than once. So I cached it in a variable called <code>$els</code>. Then I made an adjustment since <a href="http://api.jquery.com/attr/" rel="nofollow">attr</a> only returns the attribute for the first matched element, and <a href="http://api.jquery.com/text/" rel="nofollow">text</a> returns a string not an array of strings. I use <a href="http://api.jquery.com/map/" rel="nofollow">map</a> to create a jQuery object containing the values you want, and then I use <a href="http://api.jquery.com/get/" rel="nofollow">get</a> to convert that jQuery object to an array:</p> <pre><code>$('a#exportPage').on('click',function(){ var $els = $('[id^="appendHeading"]'); ExportIds = $els.map(function(){ return this.id; }).get(); ExportTexts = $els.map(function(){ return $(this).text(); }).get(); $("#PrintIds").append("ObjectID:"+ExportIds+"Content:"+ExportTexts); }); </code></pre> <p>If you are trying to output each id, text pair rather than all the ids followed by all the text, you may want to rewrite it further like this:</p> <pre><code>$('a#exportPage').on('click',function(){ var textMap = {}; $('[id^="appendHeading"]').each(function(){ textMap[this.id] = $(this).text(); }); for(id in textMap) $("#PrintIds").append("ObjectID:" + id + "Content:" + textMap[id]); }); </code></pre> <p>Or even:</p> <pre><code>$('a#exportPage').on('click',function(){ $('[id^="appendHeading"]').each(function(){ $("#PrintIds").append("ObjectID:" + this.id + "Content:" + $(this).text()); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload