// .click() を使う場合
$('#my_element').click();
// .trigger() を使う場合
$('#my_element').trigger('click');
しかし、詳しい原因はわかっていないが上記の処理で発動しないケースがあった。
その場合は、DOM を取得して DOM の .click() を実行すると通る場合がある。
// DOM の click() を呼び出す
$('#my_element').get(0).click();
// .click() を使う場合
$('#my_element').click();
// .trigger() を使う場合
$('#my_element').trigger('click');
// DOM の click() を呼び出す
$('#my_element').get(0).click();
// 検索ボタン(をクリックする場合)
var searchButton = document.querySelector('input[name=search]');
var event = document.createEvent('MouseEvents');
event.initMouseEvent(
'click',
true,
true,
window,
0,
0,
0,
$(searchButton).position().left + 15, // X = 15
$(searchButton).position().top + 15, // Y = 15
false,
false,
false,
false,
0,
null
);
searchButton.dispatchEvent(event);
HTML <div id="my-div">Hello <strong>World !</strong></div>
$('#my-div').html(); // Hello <strong>World !</strong>
$('#my-div').text(); // Hello World !
var webview = $('#my-webview');
// webview 内で console.log() が使用されると consolemessage イベントが発生
webview.on('consolemessage', function(e) {
// 引数内の originalEvent.message にメッセージが渡される
console.log(e.originalEvent.message);
});
var selected = $('input[name="my_input"]:selected');
alert('選択されたのは' + selected.val() + 'です');
$(function() {
var FEED_URL = 'http://rssblog.ameba.jp/my-blog/rss20.xml';
var feed = new google.feeds.Feed(FEED_URL);
feed.setNumEntries(30);
feed.load(function(result) {
if(!result.error) {
result.feed.entries.forEach(function(entry) {
if(!/^PR:/.test(entry.title)) {
console.log(entry);
}
});
}
});
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1/i18n/jquery.ui.datepicker-ja.min.js"></script>
$.ajax('target_url', {
type: 'POST',
dataType: 'text', // text に変える
data: {
client_data: 'my_data'
},
error: function() {
// エラー
},
success: function(response) {
document.write(response);
return; // エラーを表示して抜ける
...
}
});
$.ajax('uri', {
type: 'POST',
data: {
attr: this // "TypeError: Type error"
}
});
$('#target-img').on('load', function() {
$(this).Jcrop({
// 各種オプション
});
});
$('img[src=my_image.png]');
$('img[src="my_image.png"]');
/**
* Jcrop で選択範囲をキャンセルさせないテスト
*/
$(function() {
var api = null, // JcropAPI
selected = null; // 選択された範囲
$('#jcrop-img').Jcrop({
onSelect: function(area) {
selected = area;
},
onRelease: function() {
if(selected == null) {
return;
}
api.setSelect([selected.x, selected.y, selected.x2, selected.y2]);
}
}, function() {
api = this;
});
});
$('#target-iframe').get(0).contentWindow.myFunction();
$('#editor').prev().on('keyup', update);
$('#editor').prev().prev().on('mouseup', update);
$('#target_iframe').on('load', function() {
alert("iframe の読み込みが完了しました");
);
var src = 'http://example.com/example.jpg';
$('#target_img').attr('src', src + '?' + new Date().getTime());
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="path/nicEdit_ja/nicEdit.js"></script>
<script>
$(function() {
nicEditors.allTextAreas();
});
</script>
<style>
textarea {
width: 100%;
}
</style>
</head>
<body>
<textarea></textarea>
</body>
</html>
<textarea style="width:100%"></textarea>