Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
What is the ^= operator in jQuery?

I have come across some JS/jQuery code and am trying to find out what the ^= operator means. I can't find anything like this when Googling it.

The HTML page contains a form with these input fields:

<input type="text" id="name" name="name[1]" value="" size="22"/>
<input type="text" id="name" name="name[2]" value="" size="22"/>
<input type="text" id="name" name="name[3]" value="" size="22"/>

The JS validates the form before sending it to the server. Can somebody explain to me how the jQuery selector that is used in the lines with val and each works (or point me to the documentation)?

jQuery("button#finish").click(function(e) {
  var error = false;
  e.preventDefault();
  if (jQuery("[name^=name]").val() != "" ) {
    jQuery("[name^=name]").each(function(){ 
      if (jQuery(this).val() == "") { jQuery(this).closest("tr").remove(); }
    }); 
    
    if ( ! error) { jQuery("#form_names").submit(); }
  }
  else { alert("Bitte mindestens eine Person zuoberst in das Formular eintragen."); }

  });

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The jQuery() function (and it's alias the $() function) take a CSS selector as an argument to determine which element(s) to operate on. The list of supported selectors is given in the jQuery API documentation.

Here, the selector [foo^="bar"] means:

[an] element whose "foo" attribute value begins exactly with the string "bar"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!