w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Find out the height of an element would have to animate max-height properly
My current Workaround: The #stuff element contains two nested divs: <div id="stuff"> <div id="a">Lorem Ipsum</div> <div id="b">Lorem Ipsum</div> </div> I am now using $('#a').outerWidth() + $('#b').outerWidth() to calculate the height I need. (cHeight in Ross' answer) Better approach: An option might be to duplicate the full #stuff div make it display none remove the max-height property (max-height: auto) then use `cHeight = $('#stuff-duplicate').height()'

Categories : Jquery

Find visible height of div element while scrolling
Try var $win = $(window); var $footer = $("#footer"); $(window).scroll(function(){ var windowHeight = $win.height(); var footerTop = $footer.offset().top - $win.scrollTop(); var visibleHeight = Math.min(windowHeight, footerTop) - 80; console.log(windowHeight +", " + footerTop + ", " + visibleHeight); }); Here is the updated jsfiddle. The logic is simple. Using window's height before footer showing. Using footer's top after footer became visible. [1] or [2] - header's height = your answer.

Categories : Javascript

How to add the height of one element to the top margin of another element using JQuery
I got it. I used an iteration of ilya's idea. I added a container around everything that wasn't the nav and added top padding that was the height of the nav. I of course accomplished this through jQuery: $("#container").css("padding-top", $("#main").outerHeight() + "px" ); It works wonderfully. Thank you!

Categories : Jquery

How to find the complexity of a program to find the length of the largest sub string?
You have two nested loops of order n (where n is the length of string), so is O(n*n) = O(n2). There are some other operations which are not important in calculating big O, e.g Split, takes O(n), but compare to O(n2) is not important, or push and pop, ... in each for loop takes O(1), but it's not important if we have multiple O(1) operations. For elaboration: We know that the first loop runs n times, but about the second loop, it will run O(n-i) time, so total running time is: Σ(n-i) = Σ n - Σ i = n2 - n(n-1)/2 = O(n^2).

Categories : Algorithm

Set height of 3 elements, taking largest value, across multiple rows
Try var $sections = $('.section-title'); $sections.filter(':nth-child(3n-2)').each(function () { var $this = $(this), $els = $this.nextAll(':lt(2)').addBack(); var sectionheight = new Array(); $els.each(function () { var value = $(this).height(); sectionheight.push(value); }); var newsectionheight = Math.max.apply(Math, sectionheight); $els.height(newsectionheight); }) Demo: Fiddle

Categories : Javascript

Try to get actual width & height of a element with jQuery
EDITED ANSWER DEMO $('#test').click(function () { var size = elementSize('#content'); $('#result').html(size.width + ' x ' + size.height + 'px'); }); function elementSize(elementId) { var html_org = $(elementId).html(); var $html_calc = $('<span>' + html_org + '</span>').css({ position: 'absolute', top: -9999, left: -9999 }).appendTo('body'); var ret = { width: $html_calc.width(), height: $html_calc.height(), }; $html_calc.remove(); return ret; }

Categories : Javascript

Can't get element height when using jQuery show scale
Try $('#elementid').click (function () { alert($('#elementid').height()); }); WORKING DEMO If the Div is intially Hidden see here.

Categories : Jquery

Best method of dynamically setting the height of an DOM element with JQuery?
From the JQuery height() documentation : The difference between .css('height') and .height() is that the latter returns a unit-less pixel value (for example, 400) while the former returns a value with units intact (for example, 400px). The .height() method is recommended when an element's height needs to be used in a mathematical calculation.

Categories : Jquery

Jquery have a parent div have the same width and height of it's child element
You could use .bind() to resize it it every time something changes... $('.imgh').bind('resize', FullWidthHeight); //Note: check the 'resize' event is relevant to imgh function FullWidthHeight() { $('.imgh').css('height', img.img_set.height()); $('.imgh').css('width', img.img_set.width()); }

Categories : Javascript

Set the largest element in each row to be one and others zero
I'm not remembering the exact syntax for saying this in MATLAB right off hand, but here is how you can do it in Python with NumPy arrays, and the syntax will more or less be exactly the same in MATLAB. You won't use the None trick I've used to expand the array dimensions, though. (Note: I used my own random set of data, not yours) In [311]: t2/t2.max(axis=1)[:,None] Out[311]: array([[ 0.96452099, 0.19900529, 1. ], [ 1. , 0.36581245, 0.91631999], [ 0.62747397, 0.96969966, 1. ], [ 0.07238682, 0.59855665, 1. ]]) In [312]: np.floor(t2/t2.max(axis=1)[:,None]) Out[312]: array([[ 0., 0., 1.], [ 1., 0., 0.], [ 0., 0., 1.], [ 0., 0., 1.]])

Categories : Matlab

jQuery - find the most inner element of the container element
The best way: function innerMost( root ) { var $children = $( root ).children(); while ( true ) { var $temp = $children.children(); if($temp.length > 0) $children = $temp; else return $children; } } var $inner = innerMost($('.container')); My original solution that works with your markup, but not any: $('.container').find(':not(:has(*))');

Categories : Jquery

Find element without class or id within element - jQuery
$('img[src="http://something.com"]').closest('span'); If you want to target only the specific span that holds image with a particular src then , you can use the above selector. But if you want to target All the td.box with span's as their descendent then the suggestion by @adeneo should work.

Categories : Jquery

JQuery - assign height of container (parent) div to child element (vertical bar)
you can't assign the value to a jquery selector that returns multiple elements. you have to change the line that reads: $(this).children(".hrLine").css('height', txt); to something like; $(this).children(".hrLine").each(function(){ $(this).css('height', txt); }); tell me if this works for you Update: changed $(this).siblings to $(this).children

Categories : Jquery

Find the Kth largest int in array
the < and > in your code is reverse in partition() as @Dietmar Kühl mentioned,by change them,it works correctly. besides,my suggestion is to use a normal partition() of quicksort as follow, for whose two index of which move in the same direction and one of them never surpasses another. It is not easy to make anyone confused. int partition(int *input, int p, int r) { int pivot,i,j,tmp; pivot = input[r]; i = p-1; for (j=p;j<=r-1;j++) { if (input[j]>= pivot) { i++; tmp = input[i]; input[i] = input[j]; input[j] = tmp; } } tmp = input[i+1]; input[i+1] = input[r]; input[r] = tmp; return i+1; }

Categories : C++

How to find pair with kth largest sum?
I start with a simple but not quite linear-time algorithm. We choose some value between array1[0]+array2[0] and array1[N-1]+array2[N-1]. Then we determine how many pair sums are greater than this value and how many of them are less. This may be done by iterating the arrays with two pointers: pointer to the first array incremented when sum is too large and pointer to the second array decremented when sum is too small. Repeating this procedure for different values and using binary search (or one-sided binary search) we could find Kth largest sum in O(N log R) time, where N is size of the largest array and R is number of possible values between array1[N-1]+array2[N-1] and array1[0]+array2[0]. This algorithm has linear time complexity only when the array elements are integers bounded by small

Categories : Performance

How to find largest values in C++ Map
I doubt there's a "Textbook Answer", and the answer is no: you can't sort maps by value. You could always create another map using the values. However, this is not the most efficient solution. What I think would be better is for you to chuck the values into a priority_queue, and then pop the first 100 off. Note that you don't need to store the words in the second data structure. You can store pointers or references to the word, or even a map::iterator. Now, there's another approach you could consider. That is to maintain a running order of the top 100 candidates as you build your first map. That way there would be no need to do the second pass and build an extra structure which, as you pointed out, is wasteful. To do this efficiently you would probably use a heap-like approach and

Categories : C++

Finding the largest element in an Array
Change the for-loop to: for (var i = 0; i < array.length; i++ ) { @plalx is right, there's one more issue, in the line: largest = array[i]); There's an unnecessary closing bracket ")" which should be removed. Apply these two changes - and the code will work.

Categories : Javascript

Find largest intersecting diagonals
There is no asymptotic better solution with regards to time complexity. A weaker problem is to check if the matrix contains any 1-cell. For this problem you clearly you have to visit every cell, which gives you O(nxm). Now this is a lower bound to the original problem, which also has O(nxm). Qed.

Categories : Algorithm

How to find the largest power of 2 less than the given number
Change res =(int)Math.pow(res, 2); to res *= 2; This will return the next power of 2 greater than res. The final result you are looking for will therefore finally be res / 2 after the while has ended. To prevent the code from overflowing the int value space you should/could change the type of res to double/long, anything that can hold higher values than int. In the end you would have to cast one time.

Categories : Java

How to find largest delta in array?
change int[] largestDelta = {0}; to int largestDelta = stocks[0]; or int largestDelta = 0; Also remember about changing the return type.

Categories : Java

For double f, float g, How to find largest int i, such that i*g <= f
I think you should try to fix the root problem (.1f too far away from .1), i.e. turn TILE_SIZE into a double, or use floats consistently everywhere. Otherwise you might get similar problems caused by minimal rounding errors throughout the code. The candidate_answer function is a hack to work around a problem that should not exist in the first place. P.S. For this particular problem, you might just want to find a formula that is more robust, i.e. isn't sensitive to minimal rounding errors in one direction only. Try to put the player in the center of its field instead of at the tile edge where it can easily fall into rounding errors: col = (int)((x + MINIMAL_STEP_SIZE / 2.0) / TILE_SIZE) (Ideally, the MINIMAL_STEP_SIZE/2 part would already be part of x instead of being added here)

Categories : Java

How to find the k largest integers in a list in O(n) time?
One easy way to do this is by turning the list into a heap and popping k times. In Python, this can be done with the heapq module. import heapq numbers = [6,1,32,8,2,1,9,77,12,-643,-6,3] def getKLargest(nums, k): nums = [-x for x in nums] heapq.heapify(nums) for _ in xrange(k): yield -heapq.heappop(nums) print list(getKLargest(numbers, 5)) print sorted(numbers, reverse=True)[:5]

Categories : List

Find largest document size in MongoDB
You can use a small shell script to get this value. Note : Following will do a full table scan var max = 0; db.test.find().forEach(function(obj) { var curr = Object.bsonsize(obj); if(max < curr) { max = curr; } }) print(max);

Categories : Mongodb

Find the largest integer in Datagridview column Vb.net
Try this Dim abcd as Integer For x As Integer = 0 to Datagrid.Rows.Count - 1 If abcd = 0 then abcd = Datagrid.Rows(x).Cells(0).Value Else if abcd < Datagrid.Rows(x).Cells(0).Value Then abcd = Datagrid.Rows(x).Cells(0).Value Endif Next MsgBox(abcd)

Categories : Vb.Net

How to find the size of the largest file in a directory?
Java 7 offers the new java.nio.* classes including a FileVisitor: http://docs.oracle.com/javase/tutorial/essential/io/walk.html I used them already, but i cant say, which solution is the better one. In my opinion you should keep your solution, because it is better to read.

Categories : Java

How to find largest number in an array using NASM
The output 2222 is correct for a 32 bit register. Each number is 8 bits, 4 numbers = 8 * 4 = 32, the max a 32 bit register can hold. This is why if you change to 64 bit registers, the full number is printed. You will need to change the displayed number into a string to display the full number.

Categories : Arrays

Program to find largest and smallest among 5 numbers without using array
#include <algorithm> #include <iostream> template <typename T> inline const T& max_of(const T& a, const T& b) { return std::max(a, b); } template <typename T, typename ...Args> inline const T& max_of(const T& a, const T& b, const Args& ...args) { return max_of(std::max(a, b), args...); } int main() { std::cout << max_of(1, 2, 3, 4, 5) << std::endl; // Or just use the std library: std::cout << std::max({1, 2, 3, 4, 5}) << std::endl; return 0; }

Categories : C++

Python Splitting string to find largest odd integer
How about a list comprehension: if len(x) == 10: oddList = [int(a) for a in x if int(a) % 2] if oddList: return max(oddList) Assuming x needs to be 10 values long; assuming you don't need an else statement. You don't need to check for int(a) % 2 != 0, because if it is zero it returns false anyway.

Categories : Python

Find the largest sum including at most two consecutive elements from an array
I would imagine putting the array into a binary tree in that order. That way you can keep track of which element is next to each other. Then just simply do an if (node is not directly linked to each other) to sum the nodes which are not next to each other. You can potentially do it with recursion and return the maximum number, makes things easier to code. Hope it helps.

Categories : Java

Android OpenCV Find Largest Square or Rectangle
There are some related questions here in SO. Check them out: OpenCV C++/Obj-C: Detecting a sheet of paper / Square Detection How do I recognize squares in this image? There is also an example shipped with OpenCV: https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/squares.cpp?rev=4079 Once you have the rectangle, you can align the picture by computing the homography with the rectangle corners and applying a perspective transform.

Categories : Android

JQuery: Find submitted search string in an element. Load into div the element containing that string
The problem is foundId = $('section:contains('+query+')').attr('id'); will not return anything since the section elements are not present in the main.html Try $(document).ready(function() { $('#search-submit').click(function(e){ var query = $("#search-box").val();; e.preventDefault(); if (query.length > 0) { $.get('info.html', function(html){ var $html = $(html); $("#info_display").empty().append($html.find('section:contains('+query+')').first()) }, 'html') } else { alert("Oops, you forgot to enter a search term."); } }); });

Categories : Jquery

JQuery can't find my div element
<html> <head> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> function modalpopup(id) { alert(id); var searchid = id; var element = $("#"+searchid ); element.dialog({ height: 340, width: 500, modal: true }); } </script> </head> <body> <a href="javascript:void(0);" id="_ctl0_MainContentPlaceHolder_DataGrid1__ctl2_HyperLinkInfo" onclick="modalpopup('_ctl0_MainContentPlaceHolder_DataGrid1__

Categories : Jquery

Find an element value with jQuery
With: $('input[name="module_id[]"').val(); jsFiddle example 1 $('.module').on('click', '.click', function () { console.log($('input[name="module_id[]"').val()); }); If you have more than one set of this block of code, use $(this).closest('.ctrl').next().val(): as in: $('.module').on('click', '.click', function () { console.log($(this).closest('.ctrl').next().val()); }); jsFiddle example 2

Categories : Javascript

css floating element increase parent height but sibling with 100% height not working
Jquery solution, here's a Fiddle $(function() { var fHgt = $('#float').outerHeight(); $('#fill').css({ height: fHgt }); }); and here's a CSS solution #container { display: table; width: 500px; background-color: yellow; } #float { display: table-cell; width: 20%; background-color: green; } #fill { display: table-cell; width: 80%; overflow: hidden; background-color: red; }

Categories : HTML

Objective-C algorithm to find largest common subsets of arrays?
You are looking for an algorithm to find the cardinality of a set intersection. Depending on your set representation, you could choose different ways of doing it. The most performant representation for this would be using bits in an integer, but if the number of possible interests exceeds 64 this may not be easy to implement. A straightforward way of implementing it would be with NSMutableSet, like this: // Prepare the individual lists NSArray *chris = @[@"bowling", @"gaming", @"skating", @"running"]; NSArray *brad = @[@"bowling", @"jumping", @"walking", @"sitting"]; // Obtain the intersection NSMutableSet *common = [NSMutableSet setWitArray:chris]; [common intersectSet:[NSSet setWithArray:brad]]; NSLog(@"Common interest count: %i", common.count);

Categories : Objective C

Find the order of numbers which will give the largest number in an array
A lexicographic sort is a good start. However, the difficulty comes in when considering that, for example, [854, 854853, 854855] needs to be sorted to [854855, 854, 854853]. One way to fix this is to define a comparator that compares concatenated versions of the numbers (i.e. comparing abc and def translates to comparing abcdef and defabc). The simplest version: // processing numbers as strings List<String> array = Arrays.asList("854", "854853", "854855"); Collections.sort(array, new Comparator<String>() { @Override public int compare(String o1, String o2) { // negative since we want biggest first return -(o1+o2).compareTo(o2+o1); } }); Test. The compare function without the overhead of actually having to concatenate the numbers, just doing the ch

Categories : Java

Can I grab the height of an unrelated element that has a dynamic height with Sass?
Sorry, but I think is not possible to get a element height with SASS (i'm not an expert in sass, but I couldn't find any option). I recommend you to do this with JavaScript: http://jsfiddle.net/9DcYn/2/ window.onload = fixHeight(); function fixHeight() { var divh = document.getElementById('leftdiv').offsetHeight; var divhnum = new Number(divh); var setheight = (divhnum - 325); document.getElementById('rightdiv').style.height = setheight + 'px'; } Hope this will help you!

Categories : CSS

Find element in jQuery with dynamic value
If I understood the requirement correctly, this will do var $checked = $inputs.filter(':checked'); var numChecked = $checked.length; $checked.filter(function () { return this.value.indexOf("Ya") != -1; }).val(function (idx, val) { return val.replace("Ya", "Y2a"); }).attr({ 'disabled': true, 'aria-disabled': true })[flag ? 'addClass' : 'removeClass']('ui-state-disabled');

Categories : Jquery

JQuery find next DOM element by id where Id is not UNIQUE
ID's must be unique or else you will get broken/undefined behavior when querying the DOM. Change toggle and accounts to classes instead. Siblings() will return you a list of all siblings of the parent of toggle. Note that accounts is one of those siblings. When you call find('.accounts'), jQuery is looking for descendants of those siblings, so it will never find accounts. Instead, just use accounts as the filter in your siblings() call: $(document).on("click", ".toggle", function () { $(this).parent().siblings(".accounts").slideToggle(500); }); Working Demo

Categories : Jquery

Find attribute and element from var with jquery?
Don't use innerHTML for this. innerHTML generates a string representation of the elements. You want to work directly with the elements. First, get a jQuery wrapper around the current target: // `mash` is a jQuery wrapper around the current target var mash = $(e.currentTarget); Now you can use CSS selectors to find content within the target and retrieve information from it. Getting the data-mashup-id value: // `id` is a string var id = mash.find("[data-mashup-id"]).attr("data-mashup-id"); Getting the image (you can get information about the image from the resulting object): // `img` is a jQuery wrapper around the `img` element var img = mash.find("img"); Getting the div with the "TitleClass": // `titleElement` is a jQuery wrapper around the `div` with the class // "TitleClass" v

Categories : Javascript



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