Sublime Forum

Add a div tag around selection

#1

Hey everyone,

So I have a web app im working on with a lot of elements. I specifically have close to a hundred

tags with a “question” class. I want to systematically add tags around every single div in my document which has that question class. Is there a simple way to do this? Each one of those
elements has quite a bit of content which would also be wrapped in that element.

My first thought was to simply select one of the divs and do something to add the tag around the selection. Is this possible? I’m just not looking forward to going through and adding them all manually.

0 Likes

#2

The specifics of what you’re asking would depend on the nature of the code and without a sample its difficult to suggest exactly.

So if you have something like this:

<div class="question">
	...
</div>
<div class="question">
	...
</div>
<div class="question">
	...
</div>
<div class="question">
	...
</div>
<div class="question">
	...
</div>
  1. Select <div class="quest (something unique enough to match all the divs you want to wrap)
  2. Press Ctrl+D several times to multiselect them, or press Alt+F3 to multiselect them all. You now have multiselections and multicursors.
  3. Press home and down. Selections disappear and your cursors are in-between each div
  4. Press Ctrl+Shift+A twice. Now your
    blocks are fully selected as separate selections.
  5. Press Alt+Shift+W to wrap each div block with a new tag. By default its a

    , but if you start typing the tag will be whatever you type.

  6. Optional, step 5 creates fields, so you can tab to highlight the contained div blocks again etc. Hit escape to break out of field mode.

The above should give you some workflow ideas for achieving what you need. If your divs all vary slightly, in place of step 1 you can use Find (Ctrl+F), optionally with a regex, and press “Find All” to match the divs you want to wrap.

Following the above with a few extra keystrokes it’s very easy to get to this, with 5 or 100 divs:

<form onsubmit="func()">
	<div class="question">
		...
	</div>
</form>
<form onsubmit="func()">
	<div class="question">
		...
	</div>
</form>
<form onsubmit="func()">
	<div class="question">
		...
	</div>
</form>
<form onsubmit="func()">
	<div class="question">
		...
	</div>
</form>
<form onsubmit="func()">
	<div class="question">
		...
	</div>
</form>

Lastly if you’re regularly creating markup with lots of repeating stuff, take a look at the Emmet plugin. A massive timesaver, it allows you to use CSS style syntax to generate large blocks of markup quickly. Eg. the above code block could be created simply by typing

(form[onsubmit="func()"]>div.question>p)*5

and hitting TAB with the cursor after the 5. This cheat sheet gives you info about what you can do with Emmet. Enjoy!

0 Likes

#3

This is awesome! Thanks for the info! I have used Emmett before and loved it, and knew there had to be a way to go about what I had in mind. Thanks for your help!

0 Likes

#4

hello, i want to learn in work in dreamweaver , so i am thinking to work with fluid grill layout, in the fluid gril i want to use div AP and set them up with % not px , is it ok ? will it work responsive like div tags

0 Likes