Style text defined in custom data attribute

Parker Richard

I'm using a jQuery function to pull two portions of text listed in a selected image's custom data attributes, "htext" for header text and and "ptext" for paragraph text. I want to style this text so I can add line breaks and change the rags of each text bit.

Is there any easy way to do this, or would I have to redesign in order to style it as regular html text?

JSFiddle: http://jsfiddle.net/huL5gnej/1/

jQuery:

    $(document).ready
$(function()
    {
    $('img').hover(function() {
       $('h5').text($(this).attr('htext'));
       $('p').text($(this).attr('ptext'));
    },function(){
       $('h5').text($('h5').data('original'));
       $('p').text($('p').data('original'));
    });

$(window).load(function() {
    $('.flexslider').flexslider({
    animation: "fade",
    slideshow: false
        });
    });

$( document ).ready(function() {
    $( "div.info-box, address, #fade" ).fadeIn( 2000 );
    });

$( "#slideshow" ).hover(function() {
    $( ".flex-caption" ).fadeToggle( "slow", "linear" );
    });

})(Query);

HTML:

            <div>
                <div>
                    <img src="http://parkerrichard.com/studiogreen/html/img/hover-here.jpg" width="50px" height="50px" class="img-responsive" ptext="Sustainable practices are an important consideration at Studio Green.  At this office building, permeable concrete unit pavers are used in the driveway. Storm water is collected through the joints in the pavers, where the water is directed and absorbed underground, recharging ground water, and reducing run-off. Energy-efficient LED outdoor lighting is also used.">
                </div>
                <div>
                    <img src="http://parkerrichard.com/studiogreen/html/img/hover-here.jpg" width="50px" height="50px" class="img-responsive" ptext="The use of materials with recycled content is another sustainable technique used at Studio Green. Steel railing has recycled content and is also recyclable, after the life of this building project. Concrete can also be specified to have recycled content, by replacing Portland cement with either fly ash or slag, both by-products of industrial processes.">
                </div>
                <div>
                    <img src="http://parkerrichard.com/studiogreen/html/img/hover-here.jpg" width="50px" height="50px" class="img-responsive" ptext="Studio Green regularly designs storm water treatment systems. Here a bio-swale is created adjacent to a parking lot. Storm water run-off from both the parking lot and the building roof are directed to the planters, which are planted with plants that will treat pollutants in the water. The planters serve to slow down water flow and encourage water to percolate into the soil, rather than over-tax the city's piped storm water system.">
                </div>
                <div>
                    <img src="http://parkerrichard.com/studiogreen/html/img/hover-here.jpg" width="50px" height="50px" class="img-responsive" ptext="Studio Green regularly uses California native plants in planting design. Native plants provide valuable habitat for native birds and insects. California native plants are also extremely well suited for landscape use because they are perfectly adapted for landscapes in California, and are often drought-tolerant and low-maintenance.">
                </div>
                <div>
                    <img src="http://parkerrichard.com/studiogreen/html/img/hover-here.jpg" width="50px" height="50px" class="img-responsive" ptext="Water is one of our most precious resources, and the designers at Studio Green realize the importance of designing landscapes that conserve and improve our water. Here is an example of a bio-filtration planter that is used to treat storm water run-off from a building roof.">
                </div>
                <div>
                    <img src="http://parkerrichard.com/studiogreen/html/img/hover-here.jpg" width="50px" height="50px" class="img-responsive" ptext="Studio Green understands the use of micro-climate appropriate plantings    to both beautify and rehabilitate landscapes. Here the use of low-water requiring, native plants supports habitat for wildlife and pollinators.">
                </div>
            </div>
            <div class="info-box office-box pull-right">
                <span class="glyphicon glyphicon-chevron-right gob"></span>
                <div class="change-box">
                    <p data-original="Studio Green understands the use of micro-climate appropriate plantings to both beautify and rehabilitate landscapes. Here the use of low-water requiring, native plants supports habitat for wildlife and pollinators.">Studio Green understands the use of micro-climate appropriate plantings to both beautify and rehabilitate landscapes. Here the use of low-water requiring, native plants supports habitat for wildlife and pollinators.</p>
                </div>
                    </div>

CSS:

.elements-add {
    margin-right: 15px !important;
}

.office-box {
    width: 225px !important;
}

.info-box {
    text-align: left;
    font-size: 11px;
    font-weight: 400;
}

.change-box {
    height: 220px;
}

.info-box h5 {
    padding-bottom: 13px;
    font-size: 13px;
    font-weight: 600;
}
Tomasz Frankowski

You can use .html() instead of .text() and use HTML markup.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Use custom font in style attribute

From Dev

Select custom attribute to set style

From Dev

Why the app crashes, when I trying to set a text size attribute via custom style

From Dev

custom text style with two color

From Dev

custom text style with two color

From Dev

Use CSS to access style custom attribute

From Dev

jQuery Custom events for data attribute

From Dev

Number of core data objects with a defined attribute value

From Dev

Data extraction from user defined attribute

From Dev

SSIS Text file destination with a custom defined formatting

From Dev

Match text style and padding of custom preference

From Dev

Unable to style <li> element text with custom bullet

From Dev

Show ToolTip (with custom style) of TextBlock Text

From Dev

Converting custom text style code to html

From Dev

Error with custom text-view attribute

From Dev

Error with custom text-view attribute

From Dev

CSS how to style the "content"/"background" attribute of a custom checkbox tick sign?

From Dev

Class vs data- vs Custom attribute

From Dev

Update custom data attribute name in jquery

From Dev

CSS selector for custom data-attribute?

From Dev

Adding class to element with matching custom data attribute

From Dev

Custom data attribute not working inside <select> tag

From Dev

Count length of custom data attribute with jquery

From Dev

Custom data attribute not working inside <select> tag

From Dev

Using custom html data attribute in Thymeleaf/Springboot

From Dev

Apply css to tr with custom data attribute in JQuery

From Dev

grab data from a custom attribute on <img tag

From Dev

jQuery get multiple data from custom attribute

From Dev

How to add text in the data attribute using jQuery?

Related Related

HotTag

Archive