w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How do I take a JS array that has some elements that are also arrays and make ALL array elements top level elements
You don't need the second step to have an array of arrays, just join then split it by the comma: var array = ["item1", "item2", "item3, item4", "item5", "item6"] console.log(array.join(',').split(',')); Example fiddle

Categories : Javascript

Deleting elements of a dynamic array one-by-one
You cannot delete the elements individually. When you allocate with new [] you must deallocate with delete []. What you are doing here: int *n=new int[1]; delete n; // ERROR: should be delete [] it not correct. You are invoking undefined behaviour. It seems to work by pure chance and cannot be relied on. As for a workaround, it isn't clear what the problem is, but if you want to "move" the array, you could just assign it to a different pointer: int* n=new int[2]; ... int* m = n; n = nullptr; .... delete [] m;

Categories : C++

Create an array or object of elements with the same dynamic class
I would do this : var map = [].reduce.call(arr, function(map, v){ (map[v.className]||(map[v.className]=[])).push(v); return map; }, {}); var arr2 = []; for (var className in map) arr2.push(map[className]); The reduce builds a map having as keys the class names and with values the arrays of the elements having that class name. I use [].reduce.call(arr, instead of arr.reduce( so that it works for standard arrays, jQuery collections, nodelists, etc. Then the loop builds an array from that map. You might find the map more useful than the final array.

Categories : Javascript

Comparing class member array elements and main elements
Your canswers member is not a valid declaration. It is likely using an extension provided by your compiler to support the C flexible array member. This will act like a 0 sized array, and your access to the canswers variable are thus reading and writing beyond the object boundary, resultig in undefined behavior. You should either declare canswers with the right array size, or allow it to be a vector<char> or array<char, 20> instead. For vector<char>: class TestGrade { public: void setKey(char []); void grade(char []); std::vector<char> canswers; void display(); }; If you use vector<char>, you would need to change how you implement setKey(). void TestGrade::setKey(char answers[]) //setting values from "key" array in main { canswers.clear

Categories : C++

Efficient way to check if elements of an array is a substring of elements in another array
die if @array1 != @array2; for (0..$#array1) { die if $array2[$_] ne qq{Name: creating "$array1[$_]"}; } or if the Name part is variable, die if @array1 != @array2; for (0..$#array1) { die if $array2[$_] !~ /: creating "Q$array1[$_]E"$/; }

Categories : Arrays

Take all elements of .Split (' ') and take last OR exclude last item
Splitting the string is a bit too much here. You just need to find the last occurence of " " and split at this position: var address = "At the gates 42"; var idx = address.LastIndexOf(' '); var street = address.Substring(0, idx); var number = address.Substring(idx + 1); Also consider using regular expressions if you need more flexibility.

Categories : C#

How to exclude styles for a some specific elements using css?
Use the direct descendant selector >. It only selects the immediate descendants of the targeted parents. You could use #specificdiv ul > li and it will only select li on the first level of children. And as BoltClock pointed out, you should wrap the li whose parent is a li inside of a ul. <div id="specificdiv" class="top-bar"> <ul> <li> <ul> <li class="dropdown active"> <li class="dropdown active"> <li class="dropdown active"> </ul> <li> </ul> </div>

Categories : HTML

Exclude some elements from ajax process
for example you can call a js function with command button and capture all the elements that you wanna send. ex: <script type="text/javascript"> <!-- function call(a, b, c, d...) { addDocument(a); ..... } --> </script> <a4j:jsFunction name="addDocument" action="addDocument" reRender="panellImatge" ajaxSingle="true"> <a4j:actionparam name="idDocument" assignTo="#{crearUsuarisBB.newDocumentId}" /> </a4j:jsFunction> and in command button call --Call(); I hope it helps.

Categories : Ajax

using XPath: how to exclude text in nested elements
div[@class = 'unique_id']/text()[not(normalize-space() = '')] or div[@class = 'unique_id']/text()[last()] depending on context. Note that you still have to trim the resulting text node.

Categories : HTML

How to exclude some elements on body mouse move?
You can select and cache the elements that should be excluded and use jQuery .index() method and target property of the event object. var $blackList = $('#elem, #elem2, #elem3'), timeout = ''; $(document).on("mousemove", function(e) { // Removing last timout using ID returned by setTimeout(if any) clearTimeout(timeout); // Setting timeout using setTimeout function, // so the handler is executed once during each specified duration timeout = setTimeout(function() { // event.target returnes target element of the event // if the index of the element in jQuery collection(an array of elements) is -1 // execute the specified code if ($blackList.index(e.target) === -1) { // ... } }, 50); // change the duration according

Categories : Javascript

Can I exclude elements from being masked with -webkit-mask-image?
By the looks of things,it masks everything inside the wrapper. Your best bet would be to do something along the lines of <div id="wrapper"> <div id="excluded"></div> <p>Some very long text, that is masked on the left.</p> </div> checkout this fiddle to see it in action.

Categories : HTML

How to exclude line height for visibility hidden td elements
As you commented, you are redundant to use display: none; and if you want to achieve this by only CSS, the best you can do is, use the below CSS rule table tr td:first-child { font-size: 0; padding: 0; } Demo Note: You are using border="1" cellspacing="1" which is resulting in a thick border to the left of the table.

Categories : CSS

Exclude elements from vector based on regular expression pattern
Edit: From the comments, and with a little testing, one would find that my suggestion wasn't correct. Here are two correct solutions: vector[!grepl("['pyfgcrl]", vector)] ## kohske grep("['pyfgcrl]", vector, value = TRUE, invert = TRUE) ## flodel If either of them wants to re-post and accept credit for their answer, I'm more than happy to delete mine here. Explanation The general function that you are looking for is grepl. From the help file for grepl: grepl returns a logical vector (match or not for each element of x). Additionally, you should read the help page for regex which describes what character classes are. In this case, you create a character class ['pyfgcrl], which says to look for any character in the square brackets. You can then negate this wi

Categories : Regex

How to replace elements in array with elements of another array
You can use the splice method to replace part of an array with items from another array, but you have to call it in a special way as it expects the items as parameters, not the array. The splice method expects parameters like (0, anotherArr.Length, 1, 2, 3), so you need to create an array with the parameters and use the apply method to call the splice method with the parameters: Array.prototype.splice.apply(arr, [0, anotherArr.length].concat(anotherArr)); Example: var arr = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; var anotherArr = [ 1, 2, 3 ]; Array.prototype.splice.apply(arr, [0, anotherArr.length].concat(anotherArr)); console.log(arr); Output: [ 1, 2, 3, 'd', 'e', 'f', 'g', 'h', 'i', 'j'] Demo: http://jsfiddle.net/Guffa/bB7Ey/

Categories : Javascript

Sum of the value of dynamic elements
The keyup is only working for the first element. The new inputs are not having the handler bound to them. Instead of using .each() to bind the elements once on page load, use .on() to handle those that are also dynamically attached. Change $(".input_ttotal").each(function() { $(this).keyup(function() { calculateSum(); }); }); To $("form").on('keyup', '.input_ttotal', function() { calculateSum(); }); Click to see it in action: http://jsfiddle.net/ByLrz/1/

Categories : PHP

How to convert array with elements utf8 strings to NSArray with elements utf8 strings in objective c
I assume utfStringArray is terminated with a NULL, else you'll need to provide the element count separately. I am also assuming ARC. Note I am using NSData as you have stipulated that NSString's cannot be used (for some reason): unsigned char **utfStringArray = ...; NSMutableArray *array = [[NSMutableArray alloc] init]; for (unsigned i = 0; utfStringArray[i] != NULL; i++) { NSData *data = [NSData dataWithBytes:utfStringArray[i] length:strlen(utfStringArray[i])]; [array addObject:data]; }

Categories : Objective C

Adding tabindex to dynamic elements
this works correct for me : <html> <head> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $(':input:visible, .tabIn').each(function (i) { $(this).css('background-color','red').attr('tabindex', i + 1); }); }); </script> </head> <body> <span class="tabIn">my span</span> <input name="tabIn" /> </body> </html>

Categories : Jquery

Dynamic Div ID and Creating Elements Inside it
This does not do what I think you think it does: var theDiv = $("#projectsList"+divID).attr('id'); //document.getElementById('projectsList'); You should do var theDiv = $("#projectsList"+divID)[0]; to get the DOM element. Or, for this scenario, just do var theDiv = document.getElementById("projectsList" + divID); Also, I'm not sure why you are mixing raw DOM operations and jQuery wrapped operations everywhere. Just stick to one of them, and be consistent.

Categories : Javascript

Delegated event handler for a set of dynamic elements
$(document).ready(function(){ $('#data1').on('change','[id^=title],[id^=url]',function(){ var index = $(this).attr('id').replace('title',"").replace('url',""); var title = $("#title" + index).val(); var url = $("#url" + index).val(); var hid = $("#hid" + index).val(); // you can put in here in sequence all the fields you have $.post('library/edit.php',{title:title, url:url, hid : hid},function(res){ alert ("updated !"); }); }); }); so by this answer if any text box whoes id starts with title changes. the function passed in will be invoked. indezx variable will store the index of the group of the elements that are changing. and then is being callculated by removing title from title1 or title2

Categories : Javascript

Parsing XML elements with dynamic namespace prefix in PHP
You should use DOM - personally I believe this is true for the general case because "simple XML" is an oxymoron, but I know others disagree. It is certainly true when dealing with a complex document tree like SOAP. DOM provides getElementsByTagNameNS() (and other relevant NS-targeting methods) which allow you to specifiy the namespace URI (i.e. the thing that should remain static and be known ahead of time) instead of being specific about the prefix. $soapNsUri = 'http://schemas.xmlsoap.org/soap/envelope/'; $myNsUri = 'http://xyz.gov/headerschema'; $doc = new DOMDocument; $doc->loadXML($myRequest); $header = $doc->getElementsByTagNameNS($soapNsUri, 'Header')->item(0); $myHeader = $header->getElementsByTagNameNS($myNsUri, 'myHeader')->item(0); $sourceID = $myHeader->ge

Categories : PHP

Creating and linking dynamic elements simultaneously
You are incrementing the index after the assignment you need to use ++index instead of index++ $(".target-1").append( $("<span/>", {class: "foo", id: "s-" + ++index})); // Here $(".target-2").append( $("<span/>", {class: "bar s-" + index})) }); Fiddle Post-Increment operator will assign first and then increment. You need pre-increment operator.

Categories : Javascript

how to avoid duplicated dynamic id on partialViews elements
Add a prefix to each different item public static void RenderPartialWithPrefix(this HtmlHelper helper, string partialViewName, object model, string prefix) { helper.RenderPartial(partialViewName, model, new ViewDataDictionary { TemplateInfo = new System.Web.Mvc.TemplateInfo { HtmlFieldPrefix = prefix } }); }

Categories : Asp Net Mvc

HTML (table) elements with dynamic controls?
You have different ways: 1. Use only one row to add or edit a record and use a gridview or repeater to show data 2. use gridview in editmode (but i'm not expert about this) 3. you can put controls in gridview or repeater and manage all events using item/rowcommand

Categories : C#

CSS style difference between static and dynamic elements
My strong assumption is that you have a CSS styling element out there you are not thinking of. That's been my experience when I've been stuck like that. Using Chrome or Firefox inspect the element you have. You've already said it is not the divs but it sounds like that wouldn't be the issue anyway. Start with your td, then move to tr, then to table. Margins and padding might be your biggest culprits, but look for any attributes, including min-heights, and things along those lines. Let me know if this helps.

Categories : Javascript

How to bind bootstrap popover on dynamic elements
Update If your popover is going to have a selector that is consistent then you can make use of selector property of popover constructor. var popOverSettings = { placement: 'bottom', container: 'body', html: true, selector: '[rel="popover"]', //Sepcify the selector here content: function () { return $('#popover-content').html(); } } $('body').popover(popOverSettings); Demo Other ways: (Standard Way) Bind the popover again to the new items being inserted. Save the popoversettings in an external variable. Use Mutation Event/Mutation Observer to identify if a particular element has been inserted on to the ul or an element. Source var popOverSettings = { //Save the setting for later use as well placement: 'bottom', container: 'body', html

Categories : Javascript

Calling ko.applyBindings on dynamic elements not working
The main reason that the html binding doesn't bind the inserted html is because it can be unsafe. But if you know it's safe, you can use a custom binding that does bind the contents. Here's an example from another SO question: http://stackoverflow.com/a/17756777/1287183 Fiddle: http://jsfiddle.net/Mps4Q/9/

Categories : Javascript

In Firefox SPAN elements cannot be dynamically added to elements with -column-width values
Solved it. As I suspected, its a matter of forcing Firefox to redraw elements. The problem is fixed after adding the following line to the addSpan( ) function. document.getElementById("content").innerHTML = document.getElementById("content").innerHTML;

Categories : HTML

String gsub - Replace characters between two elements, but leave surrounding elements
You can do it using this character class : [^/] (all that is not a slash) and lookarounds mystring.gsub(/(?<=start/)[^/]+(?=/end)/,"7")

Categories : Ruby

Do elements with "position: absolute;" behave as block-level elements?
A <div> element is not inline while a <span> element is. Here's the definition of absolute from position: absolute - The element is positioned relative to its first positioned (not static) ancestor element. So the answer to your questions is yes: span elements with display: block display as somewhat block-level elements. Let me know if you still need clarification.

Categories : CSS

Dynamically adding elements to jQuery Mobile , when these elements are retrieved Asynchronously?
Try to populate your list where you're building your albums arrays. var myList = $("ul"); // better save this in a var for (i=0; i<response.data.length; i++) { myList.append('<li><img src="' + response.data[i].cover_photo + '" /><h2>' + response.data[i].name + '</h2></li>').listview('refresh'); } Also, it seems you won't need these data arrays anymore unless you plan to do some additional things with it.

Categories : Jquery

alternative to a for loop for replacing a subset of elements in a matrix with elements in a vector in R
The items you are comparing are of different classes: character and Dates. (I get an entire matrix filled with 1's.) Try this: mydates <- as.Date(mydates) # then the comparisons will more sensible It get to a vectorized answer I resorted to the use of outer and rearranged the logic a bit to create a matrix with the "new" values, and then set the failing items back to strating value of 1: myarray2 <-matrix(mycons, nrow=length(dates), ncol=length(mydates), byrow=TRUE) myarray2[ outer(dates, mydates, "<=") ] <- 1 myarray2 I tried using mapply thinking I could do something like to pass "parallel items" from two sequences but there is no way that I could get the "i" indexing to take hold. mapply(function(x,y) {myarray[i , ] <- y[x>dates]} , mydates,

Categories : R

Change text of elements identified by dynamic XPath
Oki, I found out how, and I will write the answer here maybe someone sometime will need this: <xsl:template match="/"> <!-- static parents --> <a:Root> <xsl:apply-templates select="/a:Root/a:Parent" /> </a:Root> </xsl:template> <xsl:template match="@*|*|text()"> <xsl:variable name="x" select="generate-id(../.)" /> <xsl:variable name="y" select="//field[generate-id(xalan:evaluate(xpath)) = $x]" /> <xsl:choose> <xsl:when test="$y"> <xsl:value-of select="$y/newValue" /> </xsl:when> <xsl:otherwise> <xsl:copy> <xsl:apply-templates select="@*|*|text()" /> </xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template> And to explain the t

Categories : Xslt

Selecting specific dynamic elements. jQuery / HTML
add this reference to your onclick handler try this html <a data-ajax="false" onclick="showPanel(this);" class="job"> //---------------^^^^---here jquery function showPanel(obj){ $(obj).find('div.optionPanel').toggle(); }; OR avoiding inline function $('a.job').click(function(){ $(this).find('div.optionPanel').toggle(); });

Categories : Jquery

JQuery - Loop through dynamic elements on custom event
This seems to work ok with this jsfiddle: http://jsfiddle.net/KEMrX/ It has the following javascript: $("#grid").on("custom",".grid_elm",function(){ $.each($(".grid_elm"),function(){ console.log($(this)); }) }) //"custom" Event is fired after grid refreshes with new content $(".grid_elm").trigger("custom"); and the HTML code: <div id="grid"> <div id="gridMask"> <div id="mCSB_1"> <div class="mCSB_conatiner"> <div class="holder"> <div class="grid_elm"></div> <div class="grid_elm"></div> <div class="grid_elm"></div> <div class="grid_elm"></div> </div> </div> </div&g

Categories : Jquery

Why is angular.js not smart enough to compile DOM when adding dynamic elements?
Why are you calling jquery outside of angular? Normally you would do something from inside an angular directive for instance and that would have access to $compile. If you absolutely need access outside you can create an injector. (PLUNKER) angular.module('myApp', []).directive('test', function($compile) { return { restrict: 'E', link: function(scope, element, attributes) { $(element).html('<h1>this is a test!</h1>') } } }); /////////////////////////////////////////////////////////////////////////////// // called outside angular, you can create an injector that knows about // certain modules /////////////////////////////////////////////////////////////////////////////// $(function() { // myApp for test directive to work, ng for $compile var $injec

Categories : Javascript

Dynamic columned HTML page layout using DIV elements
Please see the fiddle below http://jsfiddle.net/TCdsK/7/ Updated Fiddle to make sure two columns are of same height http://jsfiddle.net/TCdsK/14/ I hope this is it, haha

Categories : CSS

What best way to populate java list with separate elements and elements from other lists?
You could at least introduce a loop: List<WebElement> containers = Arrays.asList(inetConnection, wiredConnection, phonesConnection, usbConnection, wifiConnection); List<WebElement> list = new LinkedList<WebElement>(containers); for (WebElement e : containers) list.addAll(e.getExpectedElements());

Categories : Java

Removing elements that have no attributes, child elements, or text during transform
This should do the job: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/> <xsl:strip-space elements="*"/> <!-- Elements/attributes to remove. Note that comments are not elements or attributes. Since there is no template to match comments they are automatically ignored. --> <xsl:template match="@*[normalize-space()='']|info|@file_line_nr|@file_name"/> <!-- Match any attribute --> <xsl:template match="@*"> <xsl:copy> <xsl:apply-templates select="@*"/> </xsl:copy> </xsl:template> <!-- Match any element --> &l

Categories : Xml

Backbone Collection Set method remove existing elements and then add all elements
From the docs The set method performs a "smart" update of the collection with the passed list of models. If a model in the list isn't yet in the collection it will be added; if the model is already in the collection its attributes will be merged; and if the collection contains any models that aren't present in the list, they'll be removed. It is also a good idea to provide `idAttribute' to the model so that the collection identifies that based on the id. Otherwise the collection would not know if the model is a new one or not. So after setting the id and using set, you can see that is performs a smart update $(function () { var MyModel = Backbone.Model.extend({ // This attribute should be set as a default defaults: { Name: '' },

Categories : Backbone Js

extract elements from list of lists with variable number of elements and NAs R
So this can be marked as answered: SimonO101's solution (checking for NA values): lapply(mytestlist, function(x) { if( all(is.na(x)) ){ c(a=0,b=1,c=0) } else { x$nums } }) My solution (checking for named list elements): lapply(mytestlist, function(x) { if('nums' %in% names(x)) { x$nums } else { c(a=0, b=1, c=0) } })

Categories : R



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.