Search Results

Search found 668 results on 27 pages for 'addclass'.

Page 16/27 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • jQuery + Validation plugin: add/remove class to/from element's parent

    - by FreekOne
    Hi guys, I'm working with the jQuery Validation plugin and I wrote the following code which adds a class to the element's parent if not valid (as well as inserting the actual error message at a particular location within the parent): errorPlacement: function(error, element) { element.parent().addClass('error'); error.insertBefore(element.parent().children("br")); } This works, however, if a field's content is corrected and becomes valid, the class obviously doesn't get removed from its parent (actually, neither does the error element, instead it just gets a display: none; CSS property). How can I check if an element becomes valid and remove its parent class if so ? Any help would be much appreciated, thank you !

    Read the article

  • How to validate a form with jQuery?

    - by vlad
    I tried to find the answer in other questions but actually nothing worked -.- Somehow I hate JavaScript ... Anyway! My Code looks like: function validate() { if ($(":input").length == 0) { $(":input").addClass("notvalid"); return false; } else { $(":input").removeClass("notvalid"); return true; } return true; } $(":input").blur(validate()); $(":input").keyup(validate()); $("#customForm").submit(function(){ if(validate()){ return true; } else { return false; } }); I just want to test every tag to be not empty. The test should be done when the focus is lost or after every key type. And of course after the submit button has been clicked. It doesn't work. Firefox error console says something like: unknown pseudoclass or pseudoelement 'input'. What does this mean?

    Read the article

  • Jquery Exclude a Selector?

    - by Wes
    I've got a form that I clear on focus. I've selected the whole form and it works great except that the submit button goes blank when I click it. how can I exclude my input of input#submit from the following code? $(".wpcf7-form input, .wpcf7-form textarea").focus(function() { if( this.value == this.defaultValue ) { this.value = ""; $(this).addClass('filled'); } }).blur(function() { if( !this.value.length ) { this.value = this.defaultValue; $(this).removeClass('filled'); } });

    Read the article

  • Adding delay to mouse out function.

    - by Wazdesign
    I have one drop down menu, <ul> <li><a>link 1</a> <ul><li><a>link 1</a></li></ul> </li> </ul> I am using the following JS to use hover and show child menus. I want to add delay to the mouse out function (when the class of the LI removed) about 500ms, $('li').hover(function(){ $(this).addClass('over'); }, function(){ $(this).removeClass('over'); }); Please do needful in this. thanks in advance

    Read the article

  • Managing active state (jQuery)

    - by Nimbuz
    <ul> <li><a href="#">item 1</a></li> <li><a href="#">item 2</a></li> <li><a href="#">item 3</a></li> </ul> On click, I'd like to addclass active to the parent li element while also removing the active class from any other element which may be active already. Thanks!

    Read the article

  • limit number of characters entered in textarea

    - by Abu Hamzah
    here is the script does what i want but not exactly, my question is, how can i stop user entering text once it reached the lmit of 255 characters? var limit = 255; var txt = $('textarea[id$=txtPurpose]'); $(txt).keyup(function() { var len = $(this).val().length; if (len > limit) { //this.value = this.value.substring(0, 50); $(this).addClass('goRed'); $('#spn').text(len - limit + " characters exceeded"); return false; } else { $(this).removeClass('goRed'); $('#spn').text(limit - len + " characters left"); } }); if there is a better way please let me know.

    Read the article

  • Jquery effect problem : How to detect if mouseover is triggered by scroll ?

    - by Crupuk
    Hello, I have another problem, and because the reply is to fast here i come back again !! I would like to use "key navigation" and for that, i use the keypress event with down/up key ) When my mouse is over a div (div who's contenaing a big table) and i pull the down key : i scroll to next td + change css style + remove the current style And again, for each event.. So, because my mouse is over the main div, each time i scroll (auto) to a element, the mouseover event is triggered .. And so, the effect is missed.. This is the perfect script : User use keyboard navigation : Mouseover is disabled (so style change only with up/down key) User don't use keyboard : mouseover change the style Could you help me ? The code : $("#content tr").mouseover(function() { $("#content tr.use,#content tr.sel").removeClass("use sel"); $(this).addClass("sel"); }); And the keyboard navigation code : http://pastebin.com/Hgn5Y1FV (Sorry again for my english.. ) Thanks

    Read the article

  • jQuery click event not working when mouse moves from one div to another with button held down

    - by Acorn
    I've made a page that uses jQuery to allow you to place <div>s on the page based on your mouse coordinates when you click. The page And here's the javascript: $('document').ready(function() { $("#canvas").click(function(e){ var x = e.pageX - this.offsetLeft; var y = e.pageY - this.offsetTop; $(document.createElement('div')).css({'left':x + 'px', 'top':y + 'px'}).addClass('tile').appendTo('#canvas'); }); }); I've found that if you mousedown in the div#canvas and mouseup with your pointer over a placed <div> (or vice versa) then a new <div> doesn't get placed. Why is this?

    Read the article

  • jQuery: How to find elements *without* a class set

    - by Alan
    Hey jQuery clever peeps, Why does this fail... $( 'div.contactAperson input' ).not( 'input.hadFocus' ).focus(function() { $(this).attr('value', '' ); }); ...it's meant to sniff out input's that have not got the class .hadFocus and then when one of that subset receives focus it should zap the value to null. Right now, input values are always getting zapped -- the test .not( 'input.hadFocus' ) is failing to stop execution. Btw, preceding the above code is the following code, which is working fine: $( 'div.contactAperson input' ).focus(function() { $( this ).addClass( 'hadFocus' ); }); Thanks for any cleverness - cheers, -Alan

    Read the article

  • jQuery Validation plugin: prompt for override

    - by Sam Carleton
    I have a jQuery form that has validation of a sort. It is a data entry screen with two 'recommend ranges', one is 36-84, the other 50-300. The business rules call for the values to be either blank or greater than zero, but to prompt for confirmation if the values are outside of the range listed above. I have seen some other threads that talk about setting the class="cancel" on the submit button. From what I can tell, this will simply disable the validation. I need to prompt for a "do you want to continue, yes or no?" and if no stop the submit, if yes, continue. Below is an example from the book Pro jQuery. By default the top row needs to be between 10 and 20 to submit. How would you change it so that it prompts you and if you say Yes it submits, no prevents the submit: <!DOCTYPE html> <html> <head> <title>Example</title> <script src="jquery-1.7.js" type="text/javascript"></script> <script src="jquery.tmpl.js" type="text/javascript"></script> <script src="jquery.validate.js" type="text/javascript"></script> <style type="text/css"> h1 { min-width: 70px; border: thick double black; margin-left: auto; margin-right: auto; text-align: center; font-size: x-large; padding: .5em; color: darkgreen; background-image: url("border.png"); background-size: contain; margin-top: 0; } .dtable {display: table;} .drow {display: table-row;} .dcell {display: table-cell; padding: 10px;} .dcell > * {vertical-align: middle} input {width: 2em; text-align: right; border: thin solid black; padding: 2px;} label {width: 5em; padding-left: .5em; display: inline-block;} #buttonDiv {text-align: center;} #oblock {display: block; margin-left: auto; margin-right: auto; min-width: 700px; } div.errorMsg {color: red} .invalidElem {border: medium solid red} </style> <script type="text/javascript"> $(document).ready(function() { var data = [ { name: "Astor", product: "astor", stocklevel: "10", price: "2.99"}, { name: "Daffodil", product: "daffodil", stocklevel: "12", price: "1.99"}, { name: "Rose", product: "rose", stocklevel: "2", price: "4.99"}, { name: "Peony", product: "peony", stocklevel: "0", price: "1.50"}, { name: "Primula", product: "primula", stocklevel: "1", price: "3.12"}, { name: "Snowdrop", product: "snowdrop", stocklevel: "15", price: "0.99"}, ]; var templResult = $('#flowerTmpl').tmpl(data); templResult.slice(0, 3).appendTo('#row1'); templResult.slice(3).appendTo("#row2"); $('form').validate({ highlight: function(element, errorClass) { $(element).add($(element).parent()).addClass("invalidElem"); }, unhighlight: function(element, errorClass) { $(element).add($(element).parent()).removeClass("invalidElem"); }, errorElement: "div", errorClass: "errorMsg" }); $.validator.addClassRules({ flowerValidation: { required: true, min: 0, max: 100, digits: true, } }) $('#row1 input').each(function(index, elem) { $(elem).rules("add", { min: 10, max: 20 }) }); $('input').addClass("flowerValidation").change(function(e) { $('form').validate().element($(e.target)); }); }); </script> <script id="flowerTmpl" type="text/x-jquery-tmpl"> <div class="dcell"> <img src="${product}.png"/> <label for="${product}">${name}: </label> <input name="${product}" value="0" required /> </div> </script> </head> <body> <h1>Jacqui's Flower Shop</h1> <form method="post" action="http://node.jacquisflowershop.com/order"> <div id="oblock"> <div class="dtable"> <div id="row1" class="drow"> </div> <div id="row2"class="drow"> </div> </div> </div> <div id="buttonDiv"><button type="submit">Place Order</button></div> </form> </body> </html>

    Read the article

  • jquery live() method on custom functions

    - by user271619
    I have a custom event handler, or I suppose some call it a custom jquery function. My problem is I'm trying to apply the live() method to it. But I'm not too successful. Here's a simple custom jquery function: $.fn.myFunction = function() { return $(this).addClass('changed'); } And here I use it: $('.changePlease').myFunction(); Ok, simple enough. But how do I apply the live() method to it?? I actually have no idea if that's even possible. But I do use live() for other things, like: $(".changePlease").live("click",function(){ alert("hello"); }); Any thoughts on this?

    Read the article

  • Jquery Javascript function, simple error, can't find it!

    - by CodingIsAwesome
    When my page loads it calls the function like below: <body onLoad='changeTDNodes()'> And the code it calls is below: enter code here <script src='jquery-1.4.2.min.js' type='text/javascript'></script> <script> function changeTDNodes() { var threshValue = 10; $(".threshold").each(function(elem) { if($("b",elem).innerText > threshValue) { elem.addClass("overThreshold"); } }); }); } I have the class setup correctly in CSS .overThreshold { td{font-size:72px;} th{font-size:72px;} } But no classes are being changed, whats going on? Thanks for all your help!

    Read the article

  • jquery select problem

    - by codedude
    Say I have an unordered list like so: <ul> <li>Some Text</li> <li>Some Text</li> <li>Some Text</li> <li>Some Text</li> </ul> I want to use jquery so that when I click a "li", the background changes to blue. So I do this: $('li').click(function() { $(this).addClass('active'); }); And the "active" class has as background of blue. However, I can't figure out how to make it so that when I click another "li", the other "li" that has a background of blue stops having a background of blue. I guess what I'm trying to say is how to make only one "li" have a background of blue at a time--using jquery.

    Read the article

  • jquery :last missing multiple classes

    - by mickyjtwin
    I have an unordered list, and am using jquery to find the last ul and apply a class. jQuery("ul.class1:last").addClass("lastUi"); The html is as follows: <ul class="class1"></ul> <ul class="class1"></ul> This is working fine, however it has now changed in that another class is being added to the list so the html looks like: <ul class="class1"></ul> <ul class="class1 class2"></ul> <ul class="class1"></ul> <ul class="class1 class2"></ul> The jQuery code is now not picking up the last ul with both class1 and class2 as the last element and isn't adding the lastUI class.

    Read the article

  • Print new line in the source-code with jQuery.

    - by Kucebe
    I have a simple function in jQuery that creates new elements in the DOM. the problem is in the html source code, it append every element in the same line, and it's very bad to read. function _loadNewElements(elements){ for(var i=0; i<elements.length; i++){ var fixedElement = $('<img />') var position = elements[i].position; var cssMap = { 'position': 'fixed', 'top': position.top + "px", 'left': position.left + "px" }; fixedElement.css(cssMap); fixedElement.addClass("fixedTag"); fixedElement.attr('alt', elements[i].text); fixedElement.attr('src', "elements/" + elements[i].id + ".png"); fixedElement.appendTo($('#board')); //i'd like to print something here like ("\n"); } } I tried document.write("\n") but in this context it doesn't work. Any solution?

    Read the article

  • jQuery - Change background of input field if text getting replaced

    - by ywickham
    I'm currently using jQuery to restrict a text box to number only input as follows: $('input.numbersOnly').keyup(function () { this.value = this.value.replace(/[^0-9\.]/g,''); }); I'd like to let the user know that what they are typing is being rejected by changing the background color of the field. I know that I can change the background of a field using something like this: $('input.numbersOnly').addClass('alertClass'); My question is, how do I combine the two code examples above so that the color of the field changes as the character is getting replaced? My goal is to alert the user that something is wrong with their input as they type it in the field. Thanks!

    Read the article

  • floating a div with jquery/offset - ignores href hashtag

    - by Kevin Crawley
    <script type="text/javascript"> $(document).ready(function () { var top = $('#rt_outer').offset().top - parseFloat($('#rt_outer').css('marginTop').replace(/auto/, 0)); $(window).scroll(function (event) { // what the y position of the scroll is var y = $(this).scrollTop(); // whether that's below the form if (y >= top) { // if so, ad the fixed class $('#rt_outer').addClass('fixed'); } else { // otherwise remove it $('#rt_outer').removeClass('fixed'); } }); }); </script> The problem is fairly straight forward. If I use a header redirect to a new location in the page (say half way down, I jump to #halfway after processing a php script using header("somepage.php#halfway") the div container which is handled by this script won't jump down until the page is scrolled in either direction. I know there is a solution to this, I just don't know what.

    Read the article

  • Dismiss Menu when Focus is lost, not on mouseout. jQuery

    - by Stacey
    I have jQuery that drops a menu down when its parent is clicked on, and dismisses it when they hover away from the menu. I am wanting to change the behavior so that it only dismisses if they click somewhere else on the page, or a different menu. Is this possible? jQuery.fn.dropdown = function () { return this.each(function () { $('.ui-dropdown-list > li > a').click(function () { $(this).addClass("ui-dropdown-hover"); }); $("ul.ui-dropdown-list > li > a").click(function () { $(this).parent().find("ul").show(); $(this).parent().hover(function () { }, function () { $(this).parent().find("ul").hide(); $(this).find('> a').removeClass("ui-dropdown-hover"); }); }); }); };

    Read the article

  • Abstracting the adding of click events to elements selected by class using jQuery

    - by baroquedub
    I'm slowly getting up to speed with jQuery and am starting to want to abstract my code. I'm running into problems trying to define click events at page load. In the code below, I'm trying to run through each div with the 'block' class and add events to some of its child elements by selecting them by class: <script language="javascript" type="text/javascript"> $(document).ready(function (){ $('HTML').addClass('JS'); // if JS enabled, hide answers $(".block").each(function() { problem = $(this).children('.problem'); button = $(this).children('.showButton'); problem.data('currentState', 'off'); button.click(function() { if ((problem.data('currentState')) == 'off'){ button.children('.btn').html('Hide'); problem.data('currentState', 'on'); problem.fadeIn('slow'); } else if ((problem.data('currentState')) == 'on'){ button.children('.btn').html('Solve'); problem.data('currentState', 'off'); problem.fadeOut('fast'); } return false; }); }); }); </script> <style media="all" type="text/css"> .JS div.problem{display:none;} </style> <div class="block"> <div class="showButton"> <a href="#" title="Show solution" class="btn">Solve</a> </div> <div class="problem"> <p>Answer 1</p> </div> </div> <div class="block"> <div class="showButton"> <a href="#" title="Show solution" class="btn">Solve</a> </div> <div class="problem"> <p>Answer 2</p> </div> </div> Unfortunately using this, only the last of the divs' button actually works. The event is not 'localised' (if that's the right word for it?) i.e. the event is only applied to the last $(".block") in the each method. So I have to laboriously add ids for each element and define my click events one by one. Surely there's a better way! Can anyone tell me what I'm doing wrong? And how I can get rid of the need for those IDs (I want this to work on dynamically generated pages where I might not know how many 'blocks' there are...) <script language="javascript" type="text/javascript"> $(document).ready(function (){ $('HTML').addClass('JS'); // if JS enabled, hide answers // Preferred version DOESN'T' WORK // So have to add ids to each element and laboriously set-up each one in turn... $('#problem1').data('currentState', 'off'); $('#showButton1').click(function() { if (($('#problem1').data('currentState')) == 'off'){ $('#showButton1 > a').html('Hide'); $('#problem1').data('currentState', 'on'); $('#problem1').fadeIn('slow'); } else if (($('#problem1').data('currentState')) == 'on'){ $('#showButton1 > a').html('Solve'); $('#problem1').data('currentState', 'off'); $('#problem1').fadeOut('fast'); } return false; }); $('#problem2').data('currentState', 'off'); $('#showButton2').click(function() { if (($('#problem2').data('currentState')) == 'off'){ $('#showButton2 > a').html('Hide'); $('#problem2').data('currentState', 'on'); $('#problem2').fadeIn('slow'); } else if (($('#problem2').data('currentState')) == 'on'){ $('#showButton2 > a').html('Solve'); $('#problem2').data('currentState', 'off'); $('#problem2').fadeOut('fast'); } return false; }); }); </script> <style media="all" type="text/css"> .JS div.problem{display:none;} </style> <div class="block"> <div class="showButton" id="showButton1"> <a href="#" title="Show solution" class="btn">Solve</a> </div> <div class="problem" id="problem1"> <p>Answer 1</p> </div> </div> <div class="block"> <div class="showButton" id="showButton2"> <a href="#" title="Show solution" class="btn">Solve</a> </div> <div class="problem" id="problem2"> <p>Answer 2</p> </div> </div>

    Read the article

  • Option not clickable with mouse click after focus on select

    - by Manna
    I have configured a keyboard navigation for customized selects. Here the codepen to see in action : http://codepen.io/Mannaio/pen/ebyBi?editors=001 You can use the arrows up and down inside the selects and click the option with enter or tab button. I have a problem now and these are the steps reproduce the error 1) Do Focus on Input Name 2) Press Tab 3) If you hover and then do click with the mouse in any of the select options, they can not be selected with the mouse click This is the only error, it works perfectly if you move the arrows up and down and then you press the enter o tab, i want to to be able to select the option also with the mouse click after i do the focus with the tab button in the customized select Technically the problem is that the hover with the keyboards up and down is different when i hover with the mouse in the select-options. Line 185 function setSelected(menuitem) { $("ul.select-options.active li").removeClass("itemhover"); $("ul.select-options.active li").eq(menuitem).addClass("itemhover"); };

    Read the article

  • jQuery: inherit functions to several objects

    - by Fuxi
    hi, i made several table-based-widgets (listview-kind-of) which all have the same characteristics: styling odd/even rows, hover on/off, set color onClick, deleting a row when clicking on trash-icon. so it's always the same (prototype-)code for each widget. is there a way to have the code only once then simply apply/inherit it to all widgets? 2nd, here's some of the code - could this be optimized? var me = this; $("tr",this.table).each(function(i) { var tr = $(this); tr.bind("mouseover",function(){me.hover(tr,true)}); tr.bind("mouseout",function(){me.hover(tr,false)}); tr.bind("click",function(){me.Click(tr)}); }); $("tr").filter(":odd").addClass("odd");

    Read the article

  • How do I separate functionality with Javascript code to set Timeout?

    - by GIVE-ME-CHICKEN
    I have the following code: var comparePanel = $(__this.NOTICE_BODY); clearTimeout(__this._timeout); comparePanel.addClass(__this.VISIBLE); __this._timeout = setTimeout(function () { comparePanel.removeClass(__this.CL_VISIBLE); }, 3000); } }) The following has been repeated a few times: __this._timeout = setTimeout(function () { comparePanel.removeClass(__this.CL_VISIBLE); }, 3000); I want to be able to do something like this: __this._timeout = setTimeout(comparePanel, 3000); How do I define and call that function? PS. I am very very new to JavaScript so any explanation of what is going on is greatly appreciated.

    Read the article

  • jQuery dialog box not opening 2nd time

    - by Steven
    I found this thread which basically has the same issue I have. But their solution is not working for me. The dialog appears the first time I click the submit button, but not the 2nd time. I'm opening the dialog box after a form submission. UPDATE I finally got it working. Here is the correct code: if (jQuery('#registrationforms').length > 0) { //instantiate the dialog jQuery("#dialog").dialog({ modal:true, autoOpen:false }); //Some more code here to call processRegistration function. } function processRegistration(instanceID, formData) { jQuery.post("mypath/jquery_bll.php", { instance: 'processRegistration', formData : formData, instanceID : instanceID }, function(feedback) { jQuery('#dialog').text(feedback.message); jQuery('#dialog').parent().addClass(feedback.type); jQuery('#dialog').dialog('open'); },"json"); } Since I'm dynamically applying css class, I have to make sure to add it to the outer DIV which $.dialog creates to wrap my 'dialog' DIV.

    Read the article

  • Attaching a jquery function to some textboxes

    - by diver-d
    I am a newbie to jquery and need a little help. I have created the below function which does what I want it to however when I select a textbox every other textbox are automatically selected. How do I change it and pass a parameter from the textbox so only the selected textboxes css changes on focus and blur? <script language="javascript" type="text/javascript"> $(function () { $('.myTextBox').focus(function () { $('.box.textbox').addClass("active"); }).blur(function () { $('.box.textbox').removeClass("active"); }); }); </script>

    Read the article

  • [Ext.tree.TreePanel] getNodeById does not work

    - by Moon
    Hi, I have a ext treepanel with json. var tree = new Ext.tree.TreePanel({ renderTo:'tree-container', title: 'Category', height: 300, width: 400, useArrows:true, autoScroll:true, animate:true, enableDD:true, containerScroll: true, rootVisible: false, frame: true, root: { text: 'Category', draggable: false, id: '0' }, // auto create TreeLoader dataUrl: $("#web").val() + "/category/index/get-nodes", listeners: { 'checkchange': function(node, checked){ if(checked){ categoryManager.add(node.id); //node.getUI().addClass('complete'); }else{ categoryManager.remove(node.id); // node.getUI().removeClass('complete'); } } } }); dataUrl loads the following json code [{"text":"Code Snippet","id":"1","cls":"folder","checked":false,"children":[{"text":"PHP","id":"3","cls":"file","checked":false,"children":[]},{"text":"Javascript","id":"4","cls":"file","checked":false,"children":[]}]}] when I try to find a node by console.log( tree.getNodeByid(3) ), it shows that it is undefined. Do I have a problem with my code?

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >