selectors

Only select a single element that is inside the same element | jQuery selectors

So i have a unordered list, each item in the list has a button that is suppose to toggle the post comment textarea. Unfortunately with my first attempt when u click on one Post Comment button all textareas open, then i tried to use this to make sure only one element is selected. Here is the code: <ul class="todosDisplay"> <li><span>Con...

css selector to match an element without attribute x

I'm working on a CSS file and find the need to style text input boxes, however, I'm running into problems. I need a simple declaration that matches all these elements: <input /> <input type='text' /> <input type='password' /> ... but doesn't match these ones: <input type='submit' /> <input type='button' /> <input type='image' /> <inp...

Filtering By More Than One Attribute in JQuery

Hi everyone, I am just wondering whether that is a correct syntax in JQuery : var elements = $("#contact-area input[type=text,value=something] ").get(); What I mean is how to write specify more than one parameter to and filter apart from this use : $("#contact-area (input[type=text],input[value=something])").get(); ...

Tips for writing a jQuery selector

Seems to me the most important yet tricky thing to get right when writing jQuery is the selector. What tips do you have for writing an accurate selector? ...

jquery .each loop and replace to same location?

i got help (http://stackoverflow.com/questions/1553601/jquery-select-a-tag-with-selector-from-a-text-veriable) on looping the static var and replacing it value, but just one question is left from it, is how can i replace finded tags with newly changed tags in the text area Code: var length = 30; var end = '...'; var text = `some st...

jQuery selector question

Hi there! I'm in a bit of a dilemma. I need to select div tags based on whether their children have a certain class. This is a code example of the DOM structure: <div id="container"> <div id="one"> <p>This is item one</p> <p class="special">This is a description</p> </div> <div id="two"> <p>This...

jquery selectors speed

Which of these two is better/faster? var a = $('.listItem', $('#myList')); vs var a = $('#myList .listItem'); ...

How to select only the immediate children of an element in jQuery

I'm writing an html page with some jQuery for style. So I have the following: $("table tr:odd td").css({"background-color":"rgb(233,247,255)"}); This makes every other row bluish. But just now, I put a table inside one of the cells. What happened? Well, it treated the row of the inner table as if it was a row in the outer table, and t...

Accessing child elements in a function (jQuery)

jQuery $("#myID").each(function() { $(this).dosomething; }); HTML: <div id="myID"> <div class="myClass">content</div> </div> How do I access myClass from the function? this>myClass ? ...

How to use jQuery to select IDs not in specific class

I have a jQuery script that selects all IDs with 'Phone' in them. However, I have a small part that needs to NOT select them if they are in a class. What I have, according to the way I understand it is this: $("[id*='Phone']:not('referencePhones')").doSomething(); What am I missing? .referencePhones is a parent class. ie: div cla...

Prototype Selection Help

Hey guys, I'm trying to make a small addition to a web app I use. Right now I am trying to check all of the checkboxes on the page which have class .checkBox (In case it is needed to differentiate/select). The checkboxes are descendants of divs of class .someClass, it's just that there are many divs which have that class. I want to check...

CSS reducing syntax

I'd like two different HTML elements that are at the same nesting level to have identical CSS property values. Is there an alternative to this wasteful syntax? .level1 .level2 .level3 element1 { /*rules*/ } .level1 .level2 .level3 element2 { /*rules*/ } I was thinking .level1 .level2 .level3 element1, .level1 .level2 .level3 element2...

JQuery click function not being set

I want my links not to have the weird outline and the best way I found to solve this is have a "null link" to focus on after a click. This works great when defining the onclick method inline the HTML but that is not ideal. I wrote a quick jQuery snippet to do this instead, but I am having trouble getting it to work. Here it is: <scri...

Need the class of a parent function's returned element

Hello, Somewhat new to jQuery, so excuse the attempt at properly identifying things. I need an element's id to be reflected in a selector that is a couple functions deep, and I'm not quite sure how to go about doing that. $("input[type='file'][id^='pic_']").change( //I need this element's id... function() { $("."+this.id).hi...

Is there a peformance difference between jquery selector or a variable

Lately i have been wondering if there is a performance difference between repeating the selector just over and over again or just using a var and store the selector in that and just refer to it. $('#Element').dothis(); $('#Element').dothat(); $('#Element').find('a').dothat(); or just var Object = $('#Element'); Object.dothis(); O...

jquery selection

I have the following code : $(document).ready(function() { var hash = window.location.hash.substr(1); var href = $('#nav li a').each(function(){ var href = $(this).attr('href'); if(hash==href.substr(0,href.length-5)){ var toLoad = hash+'.html #content'; $('#content').load(toLoad) } }); $('#nav li a').click(f...

if selectors chaining?

ok, im trying to animate something to different heights if a selected id has a selected class. i have the following code. function myfunction() { if ($('#homebutton').hasClass("active")); { $('#content').animate({height: "240px",opacity: 1}, 100 , hideLoader()); } if ($('#showbutton').hasClass("active")); { $('...

Getting the index of a list item with Jquery

I'm trying to find out the index number of the last list item but the jquery I'm using keeps returning -1. This is the JS and the html that I'm using. var index = $('#imageThumbnails li:last').index(this); <div id="imageThumbnails"> <ul class="gallery_demo_unstyled"> <li class="active"><img src="test-img.jpg" width="394" heigh...

jquery adding stripes to ul

Hi I'm trying to make a function that will add a striped effect to an unordered list, I've got the following so far but cant work out how the selector should work. (function($) { $.fn.stripe = function(){ this.$("li:even").css("background-color","#f00"); }; })(jQuery); $("list_id").stripe(); thnks ...

jQuery .each() not equivelant to calling a method directly on the selector?

I've never had this issue before, so I'm somewhat lost. I'm getting two different results using essentially the same underlying code. The first way is this: $(".myClassSelector").append(somejQueryObject); The second way, which doesn't appear to work the same, is this: $(".myClassSelector").each(function() { $(this).append(somejQueryO...