jquery

Best way to purge innerHTML from a Firefox Extension

无人久伴 提交于 2021-02-04 22:42:06
问题 I'm running web-ext lint and getting back a few errors like this: UNSAFE_VAR_ASSIGNMENT Unsafe assignment to innerHTML Due to both security and performance concerns, this may not be set using dynamic values which have not been adequately sanitized. This can lead to security issues or fairly serious performance degradation. The code in question is basically doing: var html = '<style>body { margin: 0; } iframe { border: none; }' + '</style><iframe src="' + URL.createObjectURL(blob) + '" width=

Best way to purge innerHTML from a Firefox Extension

旧城冷巷雨未停 提交于 2021-02-04 22:42:02
问题 I'm running web-ext lint and getting back a few errors like this: UNSAFE_VAR_ASSIGNMENT Unsafe assignment to innerHTML Due to both security and performance concerns, this may not be set using dynamic values which have not been adequately sanitized. This can lead to security issues or fairly serious performance degradation. The code in question is basically doing: var html = '<style>body { margin: 0; } iframe { border: none; }' + '</style><iframe src="' + URL.createObjectURL(blob) + '" width=

jquery fadeout current div, find next div and fade in or find last and fade in

折月煮酒 提交于 2021-02-04 21:40:41
问题 I have div class called .stage which is a stage of a questionnaire <div class="stage"> <div class="next">Next</div> </div> <div class="stage"> <div class="back">Back</div> <div class="next">Next</div> </div> <div class="stage"> <div class="back">Back</div> <div class="next">Next</div> </div> <div class="stage"> <div class="back">Back</div> </div> I am trying to write some compact jQuery that if you select next it closes the current stage and opens the next stage or if you click back it closes

How to make content take up 100% of height and width

旧巷老猫 提交于 2021-02-04 21:39:55
问题 I'm so close but I can't get this to work like I want it. I'm trying to get the header and the menu to always be visible and have the content take up the rest of the view screen and have it's own scrollbar when it overflows. The problem is that the width of the content isn't being stretched to the right and I get a scroll bar in the middle of my page. I also can't get it to take up the rest of the remaining window height, if I set the height to 100% it wants to use the whole window height

javascript global variable good practice

二次信任 提交于 2021-02-04 21:37:39
问题 I have a few variables pertaining to the height of elements an want to update them using $(window).on('resize'[...]), as well as calculate them when first loading the page so naturally I would rather make a function for doing that, instead of repeating the code. Is it bad practice to make these variables global so that I can update them with a function, or is there any other way to do this? var hSum = 0 for (var i = 0; i < content.length; i++) { var contentH = $(content[i]).height() hSum +=

jQuery: How do I sum a column of numbers with commas?

Deadly 提交于 2021-02-04 21:35:00
问题 I used the following function I found online and it works perfectly. However, when my user later asked for commas to be included in the numbers, it broke. It only adds the numbers preceding the comma. Here is the function: function sumOfColumns(tableID, columnIndex, hasHeader) { var tot = 0; $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : "")) .children("td:nth-child(" + columnIndex + ")") .each(function() { tot += parseInt($(this).html()); }); Do I need to stop the 'parseInt' piece? 回答1: I

Dynamically detect current div on page scroll in jQuery with random number of divs

我与影子孤独终老i 提交于 2021-02-04 21:29:27
问题 I have a container that have multiple a4 page (number is random) and I want to detect what page I'm currently viewing. This is my code: <div class="mycont"> <div id="page1" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0"> <h1>page1</h1> </div> <div id="page2" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0"> <h1>page2</h1> </div> <div id="page3" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0"> <h1>page3</h1> </div> </div> <div

Dynamically detect current div on page scroll in jQuery with random number of divs

﹥>﹥吖頭↗ 提交于 2021-02-04 21:29:26
问题 I have a container that have multiple a4 page (number is random) and I want to detect what page I'm currently viewing. This is my code: <div class="mycont"> <div id="page1" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0"> <h1>page1</h1> </div> <div id="page2" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0"> <h1>page2</h1> </div> <div id="page3" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0"> <h1>page3</h1> </div> </div> <div

Javascript sort items excluding some specific items

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-04 21:27:50
问题 I am trying to sort some items (sort a map) , I can sort it successfully, but I want to exclude some items based on it's attribute Right now I am sorting like this based on attribute - price return (product.attr('active') !== 'f' }).sort(function(pA,pB){ return pB.attr('price') - pA.attr('price'); }); I want to skip some items based on attr('product_id') so the listed product_id's wont be sorted based, and will be returned first. return (product.attr('active') !== 'f' }).sort(function(pA,pB){

Javascript sort items excluding some specific items

馋奶兔 提交于 2021-02-04 21:26:38
问题 I am trying to sort some items (sort a map) , I can sort it successfully, but I want to exclude some items based on it's attribute Right now I am sorting like this based on attribute - price return (product.attr('active') !== 'f' }).sort(function(pA,pB){ return pB.attr('price') - pA.attr('price'); }); I want to skip some items based on attr('product_id') so the listed product_id's wont be sorted based, and will be returned first. return (product.attr('active') !== 'f' }).sort(function(pA,pB){