I want to select an element whose id matches the href of an &lt;a&gt; element  HTML  &lt;a href="web"&gt;&lt;/a&gt; &lt;a href="app"&gt;&lt;/a&gt;  &lt;div id="web"&gt;&lt;/div&gt; &lt;div id="app"&gt;&lt;/div&gt;   jQuery  $('a').on('click', function(e) {    e.preventDefault();    var $href = $(this).attr('href');    var $id = $('div').attr('id');    $(this).addClass('active');    //HERE I WANT TO SELECT THE DIV WHOSE "id" MATCHES THE "href" of the &lt;a&gt; clicked     $('div').id($href).addClass('active'); });
121087
Is it possible using  to select all &lt;a&gt; links which href ends with "ABC"?  For example, if I want to find this link &lt;a href="http://server/page.aspx?id=ABC"&gt;
17553
I'm working with jQuery and looking to see if there is an easy way to determine if the element has a specific CSS class associated with it.  I have the id of the element, and the CSS class that I'm looking for.  I just need to be able to, in an if statement, do a comparison based on the existence of that class on the element.
42682
I'm using jQuery and I want to check the existence of an element in my page. I have written following code, but it's not working:  if($("#btext" + i) != null) {     //alert($("#btext" + i).text());     $("#btext" + i).text("Branch " + i); }   How do I check the existence of the element?
38310
Given the following classes and controller action method:  public School {   public Int32 ID { get; set; }   publig String Name { get; set; }   public Address Address { get; set; } }  public class Address {   public string Street1 { get; set; }   public string City { get; set; }   public String ZipCode { get; set; }   public String State { get; set; }   public String Country { get; set; } }  [Authorize(Roles = "SchoolEditor")] [AcceptVerbs(HttpVerbs.Post)] public SchoolResponse Edit(Int32 id, FormCollection form) {   School school = GetSchoolFromRepository(id);    UpdateModel(school, form);    return new SchoolResponse() { School = school }; }   And the following form:  &lt;form method="post"&gt;   School: &lt;%= Html.TextBox("Name") %&gt;&lt;br /&gt;   Street: &lt;%= Html.TextBox("Address.Street") %&gt;&lt;br /&gt;   City:  &lt;%= Html.TextBox("Address.City") %&gt;&lt;br /&gt;   Zip Code: &lt;%= Html.TextBox("Address.ZipCode") %&gt;&lt;br /&gt;   Sate: &lt;select id="Address.State"&gt;&lt;/select&gt;&lt;br /&gt;   Country: &lt;select id="Address.Country"&gt;&lt;/select&gt;&lt;br /&gt; &lt;/form&gt;   I am able to update both the School instance and the Address member of the school.  This is quite nice!  Thank you ASP.NET MVC team!  However, how do I use jQuery to select the drop down list so that I can pre-fill it?  I realize that I could do this server side but there will be other dynamic elements on the page that affect the list.  The following is what I have so far, and it does not work as the selectors don't seem to match the IDs:  $(function() {   $.getJSON("/Location/GetCountryList", null, function(data) {     $("#Address.Country").fillSelect(data);   });   $("#Address.Country").change(function() {     $.getJSON("/Location/GetRegionsForCountry", { country: $(this).val() }, function(data) {       $("#Address.State").fillSelect(data);     });   }); });
932
Suppose I attach an blur function to an HTML input box like this:  &lt;input id="myInput" onblur="function() { ... }"&gt;&lt;/input&gt;   Is there a way to get the ID of the element which caused the blur event to fire (the element which was clicked) inside the function? How?  For example, suppose I have a span like this:  &lt;span id="mySpan"&gt;Hello World&lt;/span&gt;   If I click the span right after the input element has focus, the input element will lose its focus. How does the function know that it was mySpan that was clicked?  PS: If the onclick event of the span would occur before the onblur event of the input element my problem would be solved, because I could set some status value indicating a specific element had been clicked.  PPS: The background of this problem is that I want to trigger an AJAX autocompleter control externally (from a clickable element) to show its suggestions, without the suggestions disappearing immediately because of the blur event on the input element. So I want to check in the blur function if one specific element has been clicked, and if so, ignore the blur event.
10870
For this dropdownlist in HTML:  &lt;select id="countries"&gt; &lt;option value="1"&gt;Country&lt;/option&gt; &lt;/select&gt;   I would like to open the list (the same as left-clicking on it). Is this possible using JavaScript (or more specifically jQuery)?
25453
I have created a 'control' using jQuery and used jQuery.extend to assist in making it as OO as possible.  During the initialisation of my control I wire up various click events like so  jQuery('#available input',              this.controlDiv).bind('click', this, this.availableCategoryClick);   Notice that I am pasing 'this' as the data argument in the bind method. I do this so that I can get at data attached to the control instance rather from the element that fires the click event.   This works perfectly, however i suspect there is a better way  Having used Prototype in the past, I remember a bind syntax that allowed you to control what the value of 'this' was in the event.  What is the jQuery way?
80302
&lt;div id="myDiv"&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt;      &lt;a&gt;...&lt;/a&gt; &lt;/div&gt;   If you wanted to select the 2nd, 3rd and 4th a tags in the above example, how would you do that? The only thing I can think of is:  $("#myDiv a:eq(1), #myDiv a:eq(2), #myDiv a:eq(3)")   But that doesn't look to be very efficient or pretty. I guess you could also select ALL the as and then do run .each over them, but that could get very inefficient if there were a lot more as.
16631
Is there any way to get the ID of the element that fires an event?  I'm thinking something like:    $(document).ready(function() {   $("a").click(function() {     var test = caller.id;     alert(test.val());   }); }); &lt;script type="text/javascript" src="starterkit/jquery.js"&gt;&lt;/script&gt;  &lt;form class="item" id="aaa"&gt;   &lt;input class="title"&gt;&lt;/input&gt; &lt;/form&gt; &lt;form class="item" id="bbb"&gt;   &lt;input class="title"&gt;&lt;/input&gt; &lt;/form&gt;     Except of course that the var test should contain the id "aaa", if the event is fired from the first form, and "bbb", if the event is fired from the second form.
22621
I have done the following code in JavaScript to put focus on the particular element (branch1 is a  element),  document.location.href="#branch1";   But as I am also using jQuery in my web app, so I want to do the above code in jQuery. I have tried but don't know why its not working,  $("#branch1").focus();   The above jquery (focus()) code is not working for div, whereas If i am trying the same code with textbox, then its working,  Please tell me, how can I put focus on a div elemnt using jQuery?  Thanks!
72487
I have an HTML element with a large collection of unordered lists contained within it. I need to clone this element to place elsewhere on the page with different styles added (this is simple enough using jQuery).    $("#MainConfig").clone(false).appendTo($("#smallConfig"));   The problem, however, is that all the lists and their associated list items have IDs and clone duplicates them. Is there an easy way to replace all these duplicate IDs using jQuery before appending?
9579
What is the difference between HTML &lt;input type='button' /&gt; and &lt;input type='submit' /&gt;?
3057
I need to change an element's ID using jQuery.    Apparently these don't work:  jQuery(this).prev("li").attr("id")="newid" jQuery(this).prev("li")="newid"   I found out that I can make it happen with the following code:  jQuery(this).prev("li")show(function() {     this.id="newid"; });   But that doesn't seem right to me. There must be a better way, no? Also, in case there isn't, what other method can I use instead of show/hide or other effects? Obviously I don't want to show/hide or affect the element every time, just to change its ID.  (Yep, I'm a jQuery newbie.)  Edit I can't use classes in this case, I must use IDs.
102024
How do I detect text inside of this, this is HTML &amp; this is XPath. I tried  HTML     &lt;span class="messageText"&gt;Hello.&lt;/span&gt; XPath     //*[@id="liveAgentChatLogText"]/span[22]/span[2]   I tried with this but it didn't work, it said no such element found.  driver.find_element(By.XPATH, '//*[@id="liveAgentChatLogText"]//*[contains(string(.), "Hello")]')
16404
I have the following HTML &lt;select&gt; element:  &lt;select id="leaveCode" name="leaveCode"&gt;   &lt;option value="10"&gt;Annual Leave&lt;/option&gt;   &lt;option value="11"&gt;Medical Leave&lt;/option&gt;   &lt;option value="14"&gt;Long Service&lt;/option&gt;   &lt;option value="17"&gt;Leave Without Pay&lt;/option&gt; &lt;/select&gt;   Using a JavaScript function with the leaveCode number as a parameter, how do I select the appropriate option in the list?
62871
If my html looked like this:  &lt;td class="controlCell"&gt;     &lt;input class="inputText" id="SearchBag.CompanyName" name="SearchBag.CompanyName" type="text" value="" /&gt; &lt;/td&gt;   How could I select #SearchBag.CompanyName with JQuery? I can't get it to work and I fear it's the dot that's breaking it all. The annoying thing is that renaming all my id's would be a lot of work, not to mention the loss in readability.  Note: Please let's not start talking about how tables are not made for lay-outing. I'm very aware of the  and try hard to use it as much as possible.
116918
When using divs when is it best to use a class vs id?   Is it best to use class, on say font variant or elements within the html? Then use id for the structure/containers?   This is something I've always been a little uncertain on, any help would  be great.