javascript

Defaultbutton div

I am just curious; does any of you have any good javascriptresources for setting defaultbutton for all elements inside a div? I have a lot of divs that executes various javascriptfunctions and I would like all of them to have their buttons script executed when enter is pressed. Thanks in advance! ...

jQuery anchor preventDefault

Using jQuery, how do I get the value from a textbox and then load a new page based on the value? For example, lets say the textbox contains "hello" on page1.php, how do I change the default behavior of an anchor tag to now load the following page2.php?txt=hello I have the following so far: <script type="text/javascript"> $(docume...

find and execute a JavaScript function that matches a string

How can I find and execute a function inside of an object based on a string parameter? see the following example: var parameters = 'people'; switch (parameters) { case 'people': people.initialize(); break; } How ca...

Script to change webpage header based on domain name

Is there an easy way to swap a file url based on domain name? I've acme.com & acme.co.uk site domains which require different header graphic but are otherwise identical content. Rather than managing two sets of files and CMS, is there a JS/php script or other method to change the header graphic url dynamically based on which domin name...

How to delete an Arrow in Joint JS Library?

I've the following challenge, when a user selects an Arrow and press delete key, I must clear the arrow. The arrow will be always related to 2 State's; when the user fires the event, I wanna know which States (start and end) the arrow is related to, and wanna clear it from the view. How can I do that? ...

Regex wordwrap with UTF8 characters in JS

Hi everybody, i've already read all tha articles in here wich touch a similar problem but still don't get any solution working. In my case i wanna wrap each word of a string with a span. The words contain special characters like 'äüö...' What i am doing at the moment is: var textWrap = text.replace(/\b([a-zA-Z0-9ßÄÖÜäöüÑñÉéÈèÁáÀàÂâŶĈĉĜ...

Weird problem with setTimeout() on Google Chrome

I searched here and found a quick solution to call an action when the user is idle on the page. It basically works well on all browsers. But when I use an alert or a confirm dialog on the page, the weird problem occurs on Google Chrome. After the alert or confirm box disappears (Pressed OK, Cancel or Cross), the idle function works une...

Does the pattern where you chain methods in your object by returning a reference to itself have a name?

In most modern OO languages chaining methods together is common, and IMHO elegant, practice. In jquery, for example, you often see code like: $('div').addClass('container').css('color', 'white').length Does writing your objects to allow this have a name? ...

Is there any jquery plugin similar to lazyload for content

I'm searching for jquery pluging where I can showing 3 table based record and on scrolling it should make ajax request for next 3-10 record. similar to lazyload but for content. any code snippet even help me. ...

JavaScript - Why function wasn't called?!

Hi! It's a weird doubt, but it goes.... I have a button in a page, that makes a Ajax request, and when i have the answer, I write it to the page and then it's called a function to adjust Page Elements. When i click the button the first time, this function isn't called, but in the next request it is. But...if I place a alert in the sco...

Can I change the ID of an HTML element using Javascript?

I have javascript variable obj which represents an element in the DOM and I wish to change its ID. I have attempted to do this by the following, which also illustrates that it does not work! obj.id = "newID"; alert(obj.id); // this gives me newID as required var element = document.getElementById("newID"); if (element != null) { alert...

How to find and replace a div in a text response from AJAX

How would I be able to find and replace a div (or other tag) in HTML which is saved as text in a variable? I get the HTML as a text response from ajax: $.ajax({ url: 'page.pgp', success: function(result) { // here I want to find certain HTML tag // in result variable and replace it with something else } }); ...

Trying to add HTML node but it doesn't appear

I've got the following javascript function: function addConfirmLine(number, strItem, strValue) { var confirmLine = document.getElementById("divConfirmation").appendChild(document.createElement("div")); confirmLine.id = "divConfirmLine" + number; var confirmItem = confirmLine.appendChild(document.createElemen...

nodeName for selected text in Javascript

I have HTML which looks something like this: <span id="text"> <span class="segment" id="first">some text</span> <span class="segment" id="sec">bla bla</span> </span> and when user selects something, I want to identify which elements he had selected. If, for example, user had selected "text bl" I need both "first" and "sec" elements...

How to get border width in jQuery/javascript

How do I parse the border width from style="border: solid 1px black;" in jQuery/javascript? $elem.css('border-width') doesn't do it. Note I need to parse the width from the css, as the element may be display:none Thanks Edit I'm not actually using an in-line style, I just wrote it that way for simplicity as I didn't realise there...

How to find out which JavaScript events fired?

I have a select list: <select id="filter"> <option value="Open" selected="selected">Open</option> <option value="Closed">Closed</option> </select> When I select Closed the page reloads. In this case it shows closed tickets (instead of opened). It works fine when I do it manually. The problem is that the page does not reload when ...

Cursor change doesn't happen as expected in Javascript/JQuery page

I have a site that have synchronous and asynchronous activities going on, when a user clicks a button the first thing the onclick method does is: $('body').css('cursor','wait'); and before the method returns I call $('body').css('cursor','auto'); The cursor only flashes the change towards the return of the method. Does anyone have ...

Is calling functions from different js files slower than from one file?

Is calling functions in different JavaScript files slowing down JavaScript processing by the browser? In other words, can I call functions from a file to another one? Or would it be better to call function in the same file? ...

How to get an DOM Element [x,y] coordinates relative to the scrollbox?

How to get an DOM Element [x,y] coordinates in javascript? Specifically, the coordinates of a button inside a scrollbox. I found this offsetLeft attribute: var elements = scroll.children; // with 12 children if (!elements.item(2)) { print("no element"); } else if (!elements.item(2).offsetLeft) { print("no attribute"); } else { ...

Launching jQuery inside object method

Hello, let's assume that we have object like this below: function foo( some_var ) { this.some_var = some_var; } Now we add some method via prototype: foo.prototype.method = function( value ) { this.some_var += value; } Then, we have method with which I have some problems: foo.prototype.problematic = function( args ) { ...