Search Results

Search found 753 results on 31 pages for 'selectors'.

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

  • 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

  • HTML/Javascript: Selecting uncles/aunts

    - by DavidR
    So I have some code, <div class="chunk" id=""> <div class="chunkContent"> <div class="textLeft" ></div> <div class="textRight" ></div> <div class="notes border">Notes...</div> </div> <div class="tools fl"> <div class="toggleNotes border">n</div> <div class="addChunk border">+</div> </div> </div> Now, the two divs nested withing div.tools are small buttons. div.toggleNotes I need to select div.notes in a javascript/jquery function. div.addChunk I need to select the fisrt div, div.chunk. Currently, I am doing this by: $(".addChunk").live('click', (function(){create_chunk(this.parentNode.parentNode)})) $(".toggleNotes").live('click',function(){toggle_notes(this.parentNode.parentNode.firstElementChild.lastElementChild)}) Is there a better (i.e., more proper) way to do this than to string together parentNotes and firstElementChild's and etc.? I'm basically looking around the DOM tab in firebug.

    Read the article

  • Tying in .addClass() with other functions?

    - by Anders H
    Assuming an accordion dropdown with the standard form of: <ul> <li> <a href="#">Main Element</a> <ul> <li> <a href="#">Dropdown Element</a> </li> </ul> </li> </ul> I'm using jQuery to expand when the parent element link is clicked: var $j = jQuery.noConflict(); function initMenus() { $j('ul.menu ul').hide(); $j.each($j('ul.menu'), function(){ $j('#' + this.id + '.expandfirst ul:first').show(); }); $j('ul.menu li a').click( function() { var checkElement = $j(this).next(); var parent = this.parentNode.parentNode.id; if($j('#' + parent).hasClass('noaccordion')) { $j(this).next().slideToggle('normal'); return false; } if((checkElement.is('ul')) && (checkElement.is(':visible'))) { if($j('#' + parent).hasClass('collapsible')) { $j('#' + parent + ' ul:visible').slideUp('normal'); } return false; } if((checkElement.is('ul')) && (!checkElement.is(':visible'))) { $j('#' + parent + ' ul:visible').slideUp('normal'); checkElement.slideDown('normal'); return false; } } ); } $j(document).ready(function() {initMenus();}); To add a class to the Main Element when clicked (aka the class is enabled anytime the dropdown is expanded) I'm trying to use .toggleClass(className) without luck, most likely to my positioning. Where can I add this element to get the desired effect?

    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

  • Can jQuery perform a compound select against the top level only? (a.k.a. "How to avoid chaining chil

    - by harpo
    Basically, is there a way to write a.children('.outer').children('.inner') without the intermediate selector? I can't write $('.outer > .inner', a) because I don't want to do full-depth search against a — I know that the .outer elements are immediate children of a. It's partly a matter of "elegance", but partly because I'm trying to avoid "throwaway" element sets. Yes, jQuery may in effect do the same thing, but it has a better chance of optimizing (at least in theory), when it knows the full query's intent.

    Read the article

  • Wrap contents of a table

    - by Hulk
    In the following table how can the text be limited may be to show only 20 characters <table><tr><td>yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy</td></tr></table> Thanks..

    Read the article

  • Adding data dynamically to a html page

    - by Hulk
    In a htmlpage using jquery or javascript how can the following be achieved? User types in a question in a textarea and press on enter button ,then the same question should be displayed dynamically in the page below the textarea and the user can enter as many questions. And when the user is done the page is submitted through a submit button Can u please give a small hint of how this can be done.. Thanks..

    Read the article

  • jQuery, selecting form elements by name, getting: Error: uncaught exception: Syntax error, unrecogni

    - by Mark Steudel
    I'm trying to select an select element by name I found this thread showing how to do it, and I followed it but I'm getting Syntax error. I'm using jquery 1.4.1, here's my code. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>TODO supply a title</title> <script type="text/javascript" src="/js/jquery-1.4.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ alert( $('select[@name="country[0]"]').val() ); }) </script> </head> <body> <form> <select name="country[0]"> <option value="23">test</option> </select> </form> </body> </html> Thanks in advance for any insight. MS

    Read the article

  • jquery select this parent from inside image.

    - by michael
    I have the following code, i'm trying to make a loader appear then the image fade in once it is loaded. I want to make the function reusable so i can just add an image to a div with the loader id and it will work. I cant figure out how to select the parent loader div from inside the image. the commented line works fine but, i think that will select all divs. i just want to select the parent loader div. can anyone help, thanks. <div id="loader" class="loading"> <img src="http://www.inhousedesign.co.nz/images10/caravan_01.jpg" style="display: none;"/> </div> $("#loader").each(function(){ var source = $(this).find("img").attr('src'); var img = new Image(); $(img).load(function(){ $(this).hide(); //$("#loader").removeClass('loading').append(this); $(this).parents("div:first").removeClass('loading').append(this); $(this).fadeIn(800); }).attr('src', source); });

    Read the article

  • jQuery: select all DIV's nested under specific DIV

    - by Chris
    I have an architecture similar to this: <div id="container"> <div>stuff here</div> <div>stuff here</div> <div>stuff here</div> <div>stuff here</div> </div> I want to, using jQuery, hide the cursor when the mouse enters #container. However as the nested divs appear on top it doesn't quite work that way. How can I hide the mouse cursor when hovering over any of the divs within #container. Below is the cursor hiding code. $('#container').mouseover(function() { $(this).css({cursor: 'none'}); });

    Read the article

  • Is it possible to use .data() as a search criteria?

    - by Andrew
    I have a pretty complex chat application going on, and there are multiple chat panes, chat entries, chat submits, etc. going on in the same window. At first I was going to do something like.... <input type="text" class="chattext" id="chattext-42"> <input type="text" class="chattext" id="chattext-93"> <input type="button" class="chatsubmit" id="chatsubmit-42"> <input type="button" class="chatsubmit" id="chatsubmit-93"> ... etc. (of course this is vastly simplified, they'd be in separate divs, separate visibilities, etc) So, when they clicked on a .chatsubmit, it would then get the id of that and find the last two characters for the chat ID. This presents some problems, as it would require rewrites if IDs changed lengths, and seems just plain inelegant to me. I then remembered the .data() facility in jQuery... I thought, maybe I could do it more like this: <input type="text" class="chattext"> ... and add a .data("id", 42) to this one <input type="button" class="chatsubmit"> ... and add a .data("id", 42) So that when they click chatsubmit, it gets the ID, and then finds the chattext with that ID and processes it. But looking at the documentation, I don't see an easy way to search by this. For example, let's say the event target in this case is the chatsubmit with the data('id') of 42... var ID = $(event.target).data('id'); // Sets it to 42 var chattext = ... And here I run into the trouble. How do I find which DOM element matches a class of chattext and a data('id') of 42? Is there any easy method, or do I have to search every .chattext for the one with an id of 42? Or is there another easy way of doing this? I did consider the possibility of the container div having the ID, which would make it, I think,? slightly easier to get. But if this works, it could be dealing with things in other container divs as well, making that not a long-term solution. Edit: Literally seconds after posting this, I found this: http://james.padolsey.com/javascript/extending-jquerys-selector-capabilities/ which includes information on extending the selector to data. So I'll try that out, and in the meantime, is this a completely foolhardy way of handling this?

    Read the article

  • jQuery toggle div and text

    - by Jack
    I would like some help with this code, I have read similar questions & answers here on stackoverflow but I still can't get it right. I have a link that populated by .html("") to read more… when clicked it opens the hidden div and at the end the .html("") reads less. When I click close the div slides closed but the text still reads less… I have read many articles on how to do this but am confused and can't get past this last hurdle, any help would be much appreciated. // this is the intro div Ligula suspendisse nulla pretium, rhoncus tempor placerat fermentum, enim integer ad vestibulum volutpat. Nisl rhoncus turpis est, vel elit, congue wisi enim nunc ultricies sit, magna tincidunt. Maecenas aliquam maecenas ligula nostra, accumsan taciti. // this next div is hidden Ligula suspendisse nulla pretium, rhoncus tempor placerat fermentum, enim integer ad vestibulum volutpat. Nisl rhoncus turpis est, vel elit, congue wisi enim nunc ultricies sit, magna tincidunt. Maecenas aliquam maecenas ligula nostra, accumsan taciti. $(document).ready(function() { $(".overview-continued").hide(); $(".show-overview").html("more..."); $(".show-overview").click(function() { $(".overview-continued").slideToggle("1000"); $(".show-overview").html("less..."); return false; }); });

    Read the article

  • jquery selector question

    - by FFish
    How can I select the src attr from the zoom span? $(".gallery span.zoom").click(function() { // var imgPath = $(this).parent()......attr("src"); // alert(imgPath); return false; }); <ul class="gallery"> <li id="li-1"> <img src="002171/tn/001.jpg" alt="image" /> <span class="delete"></span> <span class="zoom"></span> <em>hello world</em> </li> </ul>

    Read the article

  • Prototype Selector : simple examples

    - by kevinb92
    Hi, i'm just starting prototype, i was on jquery before. I can't find easy examples on the internet about how : Selecting all elements having the same id on a page (i'm doing this but it only works for the first element : $('mydiv').hide() ) Selecting a div that is contained in another div by their id. hiding all elements that have myClass class.

    Read the article

  • best way to filter out non-representational elements

    - by nonano
    Hi there, I am using phpQuery in order to apply some twaks to editorial content. As its syntax is the same as jQuery, I consider this a dom scripting issue. To get rid of elements which are not representing anything, but wrapping other stuff (like the div in <div><p>blah</p></div> I came up with this selector: ['div:not([align][class][id][style][title][dir][lang][onclick][ondblclick][onmousedown] [onmouseup][onmouseover][onmousemove][onmouseout][onkeypress][onkeydown][onkeyup])'] which looks quite monstrous for a selector simply aming on Divs which just do not have any (valid) attribute. I guess there must be a more straight-forward way to accomplish that, right? Edit: Oh, and I just noticed that it even doesn't do wat I intended to ...

    Read the article

  • Alignment for 2nd row data

    - by user1736299
    <table> <tr><td>test</td></tr> <tr> <td> <div style= height:200px;"> <div style="border:1px solid yellow; display: inline-block; width:100px"> <img src="orderedList4.png"> </div> <div align="center" style="border:1px solid green; display: inline-block; width:650px;height:100px;"> <div>center Test Header1</div> <div>center Test Header2</div> </div> <div align="right" style="border:1px solid red;display: inline-block; width:100px">REL 1.0</div> </div> </td> </tr> </table> In the above code, the image size is 75*75 pixels. I want to have all the three cells to have a height of 100 pixels. I want the image to be centered and left aligned. The middle text to centered. Third text to centered and right aligned. I could not make it working.

    Read the article

  • jquery javascript error using $(...) selector

    - by waitinforatrain
    Hi, I'm migrating some old code to jquery: xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { $("#" + ajaxArea).html (xmlHttp.responseText); $("#" + ajaxArea).attr('title', 'Login'); $("#" + ajaxArea).dialog({ height : 140, modal : true }); } }; where ajaxArea is the ID of a DIV in the HTML. The dialog bit is basically adapted from the jQuery example here: http://jqueryui.com/demos/dialog/#modal All of it works fine up until the last line. Firefox throws an error that simply says "$(" for that line. Anyone know what might be causing this?

    Read the article

  • jquery .attr('alt','logo').css('display','none') not working !!!

    - by Cesar Lopez
    I have the three following lines and the first two line gets all the images on the document and hides all, but then when I add the third line shows all the images. What I need its to hide only the images with the attribute alt=minimize and alt=maximize but for some reason hides all the images. $('img').attr('alt', 'minimize').css("display","none"); $('img').attr('alt', 'maximize').css("display","none"); $('img').attr('alt', 'logo').css("display","inline"); I am using IE7, but it should be compatible with IE6 and IE8. Any help would be very much appreciated. Thanks.

    Read the article

  • SEL performSelector and arguments

    - by madmik3
    Hello, It seems like there should be an easy way to call a selector with some arguments when all you have is a SEL object. I can't seem to find the correct syntax. -(MyClass*) init: (SEL)sel owner:(NSObject*) parent { int i =10; [parent performSelector:sel:i ]; }

    Read the article

  • jQuery child of clicked element

    - by Tom
    Hi, I've got a list of links which have a click event attached to them, I need to get the ID from the child A link. So in the example below if I clicked the first list element I'd need google retuned. I've tried '$this a' but can't quite work out the syntax. jQuery: $("ul li").click(function(event){ $("input").val($(this).html()); } ); html: <ul> <li><a href="http://www.google.com" id="google">Google</a> </ul>

    Read the article

  • jQuery: how to find first visible input/select/textarea excluding buttons?

    - by Artem
    I tried $(":input:not(input[type=button],input[type=submit],button):visible:first") but it doesn't find anything. What is my mistake? UPD: I execute this on $(document).load() <script type="text/javascript"> $(window).load(function () { var aspForm = $("form#aspnetForm"); var firstInput = $(":input:not(input[type=button],input[type=submit],button):visible:first", aspForm); firstInput.focus(); }); </script> and in the debug I can see that firstInput is empty. UPD2: I'm in ASP.NET page running under Sharepoint. I've found so far that for some elements it does find them (for fixed ones) and for some don't. :(

    Read the article

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