Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:29:13+00:00 2026-06-08T21:29:13+00:00

if a == http://foo.bar and $(b[0]).attr(href) == http://foo.bar then why does the following code

  • 0

if a == "http://foo.bar"
and $(b[0]).attr("href") == "http://foo.bar"

then why does the following code not return true:

$("[href^=\"" + a + "\"]", b).length > 0

?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:29:15+00:00Added an answer on June 8, 2026 at 9:29 pm

    Because the second parameter passed to the jQuery function scopes the selector, which is to say, find the selected element in the children of b.

    So by way of an example

    <div id="one">
       <div id="two" title="Test" />
    </div>
    

    This will return 1

    $('[title="Test"]','#one').length 
    

    This will return 0

    $('[title="Test"]','#two').length 
    

    Live example: http://jsfiddle.net/mkudf/


    Based on your comments, it seems you’re doing some stuff before adding the element to the dom, so by example:

    var $x = $('<div id="one" /><div id="two" title="Test" />');
    alert($('[title="Test"]',$x).length); // alerts "0"
    

    I can find no way of achieving what you want (The above to alert “1”) without wrapping the dynamic elements in an extra element:

    var $x = $('<div><div id="one" /><div id="two" title="Test" /></div>');
    alert($('[title="Test"]',$x).length); // now alerts "1"
    

    Which shouldnt be too much of a problem, when adding to the dom you could just take $x.children():

    $someOtherElement.after($x.children());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following code: var a = 'somegarbage=http://somesite.com/foo/bar/&moregarbage'; var result = a.match(/http.+\//g); Produces the
I have the following appSettings section <appSettings> <add key=Foo value=http://foo.bar.com/?app=xxx&FormName=yyy /> </appSettings> But the
I'm working in a non-privileged environment, and my Rails application's root url is http://foo.com/bar
I'm trying to rewrite a url of this: http://www.foo.com/bar/baz to index.php?q=$1&d=baz Where bar is
I have a JSP page at an address like this: http://example.com/foo/bar/rawr/something.jsp When I output
I have a System.Uri, e.g., var uri = new Uri(http://www.domain.com/foo/bar); How do I get
http://localhost/foo/profile/%26lt%3Bi%26gt%3Bmarco%26lt%3B%2Fi%26gt%3B The url above gives me a 404 Error , the url code is
How do i match from these urls: http://foo.bar.com http://bar.com foo.bar from the first link
Say I have my custom taglib: <%@ taglib uri=http://foo.bar/mytaglib prefix=mytaglib%> <%@ taglib uri=http://java.sun.com/jstl/core prefix=c%>
I need to exclude some URLs for a jMeter test: dont exclude: http://foo/bar/is/valid/with/this http://foo/bar/is/also/valid/with/that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.