The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.
Держите: jsfiddle.net/72u73zmm/3
По-хорошему, надо еще проверять, а не стоит ли указанный класс на элементе уже, а не просто перещелкивать его.
KeyG = game.input.keyboard.addKey(Phaser.Keyboard.G);
KeyG.onDown.add(strike, this);
function strike () {
player.body.setSize(60, 50);
}
function unStrike () {
player.body.setSize(30, 50);
}
game.physics.arcade.overlap(player, player2, figth, null, this);
function figth (player, player2) {
console.log('figth');
unStrike();
}
$("[*|title=russia]").attr('id','example');
$("[xlink\\:title=russia]").attr('id','example');
In documents comprising elements from multiple namespaces, it's possible that some elements from different namespaces share the same local name. Since this API does not natively support a namespace resolution mechanism for selectors, obtaining a list of such elements from a specific namespace, excluding all others, requires additional processing to filter the result. The following example illustrates a document containing video elements from both the SVG and XHTML namespaces.
<svg id="svg1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<video id="svgvideo1" xlink:href="myvideo.ogg" width="320" height="240"/>
<foreignObject width="100" height="100">
<video id="htmlvideo1" src="myvideo.ogg"
xmlns="http://www.w3.org/1999/xhtml">No video1</video>
</foreignObject>
</svg>
The following script demonstrates how to first select the video elements and then filter out the unwanted elements based on their namespace.
var elms = document.querySelectorAll("svg video");
var result = new Array();
var svgns = "http://www.w3.org/2000/svg"
for(var i = 0; i < elms.length; i++) {
if(elms[i].namespaceURI == svgns) {
result.push(elms[i]);
}
}