제목 속성이 있는 요소를 클릭하면 제목 텍스트가 있는 자식 요소가 추가됩니다. 예를 들어 보겠습니다 -
HTML용 -
<p> The <span class="demo" title="this is underscore">underlined</span> character. </p>
제이쿼리 -
$("span[title]").click(function () {
var $title = $(this).find(".title");
if (!$title.length) {
$(this).append('<span class="title">' + $(this).attr("title") + '</span>');
} else {
$title.remove();
}
}); 다음은 CSS입니다. -
.demo {
border-bottom: 2px dotted;
position: relative;
}
.demo .title {
position: absolute;
top: 15px;
background: gray;
padding: 5px;
left: 0;
white-space: nowrap;
}