Precautions for using the JQuery selector [attribute ^ = value], jqueryattribute
Note 1:
Precautions for using the JQuery selector in Firefox [attribute ^ = value]
A previously written script is used
var bindAttrs = $("[databind^='attr'", item);
Are you aware of the problem?
This script has been used for a while, but it has never been tested in Firefox,
It can be used normally in other browsers!
Today, someone suddenly found that the data loaded in Firefox is incorrect,
After a period of debugging, I found that there was a problem with code writing,
I made a low-level mistake. I wrote only the left brackets and forgot to write the right brackets.
NOTE 2:
Related HTML:
<div id="Zy_hotsort_img" class="Zy_hotsort_img"><div class="Zy_newicon">new</div></div>
Related JS Code:
var item = $("#Zy_hotsort_img").html();var bindAttrs = $("*[databind^='attr']", item);
The problem arises. In this way, the img element starting with attr cannot be obtained. How can this problem be written?
Statement 1:
var item = $("#Zy_hotsort_img").prop("outerHTML");var bindAttrs = $("*[databind^='attr']", item);
Statement 2:
var item = $("#Zy_hotsort_img").html();var bindAttrs = $("*[databind^='attr']", $("<div></div>").append(item));
Jquery [attribute = value] variable
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "www.w3.org/..al.dtd">
<Html xmlns = "www.w3.org/5o/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
<Style>
. On {color: # FF0000 ;}
</Style>
<Script src = "js/jquery. js"> </script>
<Script>
$ (Function (){
$ ("A"). click (function (){
Var test1 = $ (this). attr ("class") + "-img"
$ ("P [class =" + test1 + "]"). addClass ("on ")
});
});
</Script>
</Head>
<Body>
<A href = "#" class = "a1"> I am link 1, class = "a1" </a>
<A href = "#" class = "a2"> link 2, class = "a2" </a> <br/>
<P class = "a1-img"> I'm p1, class = "a1-img" </p>
<P class = "a2-img"> I'm p2, class = "a2-img" </p>
</Body>
</Html>
---------------------
That's all you can do .... Remaining full text>
Can I use a regular expression in the jquery selector?
$ ("[Class ^ = 'class _ ']")