[ 이 글은 2016년 8월 2일에 최종 수정되었습니다. ]

참고: 인기 워드프레스 테마 중 하나인 The 7이 39달러로 할인 중입니다.

You might sometimes to add a new div with a class immediately after a specific div. It will be easy to make it done if you are able to edit the html codes directly. However, if you have no access to source code, you might use jQuery. There are several methods:

var myClass = "thisIsMyClass";
var div = $("<div></div>").addClass(myClass);
$(this).after(div);

For example, you can use the above script as follows:

var myClass = "thisIsMyClass";
var div = $("<div>Text</div>").addClass(myClass);
$(".current").after(div);

Demo – jsfiddle. Of course, you can use before() instead of after() if you want the new div immediately before the existing div as follows:

var myClass = “thisIsMyClass”;
var div = $(“<div>Text</div>”).addClass(myClass);
$(“.current”).before(div);
// jsfiddle

Or, the following scripts can also be considered:

$('<div>Mr. Kim</div>',{ class : 'sample'}).appendTo(".current");

– OR –

$("<div>Mr. Kim</div>").insertAfter(".current").addClass(myClass);

You can check the working demos: sample 1sample 2.

Please feel free to leave a Comment (Comments). Have a great day.